鸿蒙开发(NEXT/API 12)【硬件(注册智慧出行连接状态的监听)】车载系统

注册智慧出行连接状态的监听,用于获取业务连接状态的变更。

接口说明

接口名 描述
[on] (type: 'smartMobilityStatus', smartMobilityTypes: SmartMobilityType[], callback: Callback): void 注册智慧出行连接状态的监听。

开发步骤

  1. 导入Car Kit模块。

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

    复制代码
    let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
  3. 注册智慧出行连接状态的监听。

    // 业务类型
    let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.HICAR];
    // 出行连接状态回调函数
    const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
    hilog.info(0x0000, 'Received smart mobility info: ', JSON.stringify(info));
    };
    // 注册智慧出行连接状态的监听
    awareness.on('smartMobilityStatus', types, callBack);

相关推荐
key_3_feng2 小时前
鸿蒙6.0技术解读
华为·harmonyos
想你依然心痛3 小时前
HarmonyOS 5.0物联网开发实战:基于星闪(NearLink)技术的智能家居边缘计算网关
物联网·智能家居·harmonyos
互联网散修4 小时前
零基础鸿蒙应用开发第二十四节:商品类重构属性契约接口
harmonyos·鸿蒙
2501_920627616 小时前
Flutter 框架跨平台鸿蒙开发 - 数据库学习助手
数据库·学习·flutter·华为·harmonyos
高心星7 小时前
鸿蒙6.0应用开发——定位功能的实现
华为·定位功能·鸿蒙6.0·harmonyos6.0·鸿蒙定位
2501_920627617 小时前
Flutter 框架跨平台鸿蒙开发 - 编程代码库应用
学习·算法·flutter·华为·harmonyos
攻城狮在此7 小时前
华三框式交换机IRF堆叠配置三(BFD MAD检测)
网络·华为·架构
Swift社区7 小时前
为什么传统手游不适合鸿蒙游戏?
游戏·华为·harmonyos
芙莉莲教你写代码8 小时前
Flutter 框架跨平台鸿蒙开发 - 疫苗接种记录
flutter·华为·harmonyos
芙莉莲教你写代码8 小时前
Flutter 框架跨平台鸿蒙开发 - 步数追踪器
flutter·华为·harmonyos