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

相关推荐
不爱吃糖的程序媛7 小时前
ArkUI-X 6.0.0 Release发布
华为·harmonyos
w139548564229 小时前
Flutter跨平台组件集成框架鸿蒙化使用指南
flutter·华为·harmonyos
进击的前栈10 小时前
Flutter跨平台开发鸿蒙化HTTP解析工具包使用指南
flutter·http·harmonyos
进击的前栈11 小时前
Flutter跨平台开发鸿蒙化HTTP测试工具包使用指南
flutter·http·harmonyos
花开彼岸天~16 小时前
Flutter跨平台开发鸿蒙化定位服务组件使用指南
flutter·开源·harmonyos
特立独行的猫a17 小时前
移植开源软件Notepad--(NDD)到鸿蒙PC:环境搭建与配置
notepad++·开源软件·harmonyos·鸿蒙pc·notpad--
俩毛豆17 小时前
【毛豆工具集】【文件】【目录操作】生成沙盒目录
前端·javascript·鸿蒙
鸿蒙开发工程师—阿辉18 小时前
HarmonyOS 上下文的使用: 脱离 UI 怎么用 Context?
ui·华为·harmonyos
FrameNotWork19 小时前
HarmonyOS 教学实战(八):后台任务、Worker 与任务调度
华为·harmonyos