鸿蒙开发(NEXT/API 12)【硬件(注册出行业务事件监听)】车载系统

注册出行业务事件监听,用于接收业务发送事件的通知。

接口说明

接口名 描述
[on] (type: 'smartMobilityEvent', smartMobilityTypes: SmartMobilityType[],callback: Callback): void 应用注册出行业务事件监听。

开发步骤

  1. 导入Car Kit模块。

    复制代码
    import { smartMobilityCommon } from '@kit.CarKit';
  2. 获取SmartMobilityEventAwareness实例。

    复制代码
    let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
  3. 注册出行业务事件监听。

    // 业务类型
    let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
    // 出行业务事件回调函数
    const callBack = (event: smartMobilityCommon.SmartMobilityEvent) => {
    hilog.info(0x0000, 'Received smart mobility event: ', JSON.stringify(event));
    };
    // 注册出行业务事件监听
    awareness.on('smartMobilityEvent', types, callBack);

相关推荐
心中有国也有家4 小时前
ArkTS 鸿蒙开发语法完全指南:从入门到实战
华为·harmonyos
云栖梦泽5 小时前
鸿蒙应用开发:网络通信与数据同步优化(上)——网络通信基础
鸿蒙系统
Georgewu7 小时前
如何判断应用在鸿蒙卓易通或者出境易环境下?
android·harmonyos
菜鸟不学编程7 小时前
鸿蒙中的 AR/VR 开发与场景创建
ar·vr·harmonyos
Swift社区9 小时前
鸿蒙应用上架流程经验
华为·harmonyos
@不误正业9 小时前
OpenHarmony集成AI Agent实战:打造鸿蒙智能助理
人工智能·华为·harmonyos
仓颉编程语言11 小时前
CangjieSkills 正式开源:为仓颉 AI 编程打造的“技能增强“方案,实测降低 60% 费用
华为·ai编程·鸿蒙·仓颉编程语言
弓.长.13 小时前
ReactNative for OpenHarmony项目鸿蒙化三方库:react-native-netinfo — 网络状态检测
网络·react native·harmonyos
腾视科技TENSORTEC13 小时前
腾视科技重磅发布AD03行车记录仪DashCam!全维守护,智驭出行新生态
大数据·网络·人工智能·科技·ai·车载系统·车载监控
弓.长.13 小时前
ReactNative for OpenHarmony项目鸿蒙化三方库:react-native-network-info — 网络信息获取
网络·react native·harmonyos