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

相关推荐
想你依然心痛13 小时前
HarmonyOS 6 悬浮导航 + 沉浸光感:打造鸿蒙智能体驱动的沉浸式会议效率助手
华为·ar·harmonyos·智能体
network_tester15 小时前
TSN网络流量及协议测试:为确定性网络护航的关键技术
网络·网络协议·车载系统·汽车·信息与通信·信号处理
●VON15 小时前
BodyAR 从零开始:开发环境搭建与完整项目配置指南
华为·harmonyos·鸿蒙·新特性
2301_7803567017 小时前
加入开源鸿蒙生态:全视通与开鸿启源共建智慧医康养新场景
harmonyos
●VON17 小时前
鸿蒙Flutter实战:Emoji心情选择器组件
flutter·华为·harmonyos
前端不太难18 小时前
鸿蒙 PC 为什么需要新的组件体系?
华为·状态模式·harmonyos
nashane18 小时前
HarmonyOS 6学习:解决图片下载后无法在图库中查看的权限与路径问题
学习·华为·harmonyos
●VON18 小时前
鸿蒙 BodyAR 技术全景解读:从芯片到应用的人体骨骼追踪
华为·harmonyos·新特性
●VON18 小时前
鸿蒙Flutter实战:列表延时错峰入场动画
flutter·华为·harmonyos