鸿蒙开发(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);

相关推荐
ifeng09187 分钟前
HarmonyOS实战项目:AI健康助手(影像识别与健康分析)
人工智能·华为·wpf·harmonyos
爱笑的眼睛1111 分钟前
HarmonyOS NFC应用开发:构建分布式近场通信解决方案
华为·harmonyos
星释6 小时前
鸿蒙Flutter三方库适配指南:09.版本升级适配
flutter·华为·harmonyos
CN-cheng18 小时前
Flutter项目在HarmonyOS(鸿蒙)运行报错问题总结
flutter·华为·harmonyos·flutter运行到鸿蒙
碧波bibo19 小时前
在编译OpenHarmony遇到third_party/libnl编译报错的修复办法
鸿蒙
平平不平凡19 小时前
鸿蒙音频播放器深度解析:从核心设计到完整实现
harmonyos
汽车仪器仪表相关领域21 小时前
汽车排放检测的 “模块化核心”:HORIBA OBS-ONE GS Unit 气体分析单元技术解析
大数据·人工智能·功能测试·车载系统·汽车·安全性测试·汽车检测
HMSCore1 天前
【FAQ】HarmonyOS SDK 闭源开放能力 — Form Kit
harmonyos
爱笑的眼睛111 天前
HarmonyOS数据存储Kit深度实践:从架构设计到性能优化
华为·harmonyos
爱笑的眼睛111 天前
HarmonyOS后台代理提醒Agent:构建智能提醒功能的深度解析
华为·harmonyos