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

相关推荐
lqj_本人5 分钟前
鸿蒙Qt数据库实战:SQLite死锁与沙箱路径陷阱
数据库·qt·harmonyos
FrameNotWork13 分钟前
#RK3588 Android 14 虚拟相机 HAL 开发踩坑实录:从 Mali Gralloc 报错到成功显示画面
android·车载系统
不羁的木木1 小时前
【开源鸿蒙跨平台开发学习笔记】Day02:React Native 开发 HarmonyOS-环境搭建篇(填坑记录)
笔记·学习·react native·harmonyos·har
坚果派·白晓明1 小时前
通过开源鸿蒙终端工具Termony完成Coremark 命令行工具构建过程深度解读
openharmony·命令行工具·开源鸿蒙·开源软件termony
坚果派·白晓明1 小时前
通过开源鸿蒙终端工具Termony完成Ncurses 命令行工具构建过程深度解读
openharmony·开源鸿蒙·开源软件termony
lqj_本人2 小时前
鸿蒙Qt网络通信:HTTPS握手失败与证书陷阱
qt·https·harmonyos
lqj_本人8 小时前
HarmonyOS + Cordova 工程搭建与目录结构:从零到跑通 & 常见报错排查
华为·harmonyos
Georgewu9 小时前
【HarmonyOS 6】在UI控件上滑动也会触发onClick点击事件?
harmonyos
Georgewu10 小时前
【HarmonyOS 6】为什么getContext 废弃,使用getHostContext说明
harmonyos
半个西瓜.10 小时前
车联网NFC测试:NFC信号嗅探测试.
网络·安全·网络安全·车载系统