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

相关推荐
Hello__77773 小时前
开源鸿蒙 Flutter 实战|页面加载进度条全流程实现
flutter·开源·harmonyos
nashane3 小时前
HarmonyOS Text组件堆叠布局中的文字缩进避让技术详解
华为·harmonyos·harmonyos 5
爱艺江河4 小时前
智慧合规的HarmonyOS原生实践:与OpenClaw适配的项目方案浅析
人工智能·华为·harmonyos
三声三视6 小时前
ArkTS Navigation 路由实战:从 Router 迁移到 NavPathStack,打造企业级路由体系
华为·harmonyos·鸿蒙
Swift社区8 小时前
System + AI:下一代 鸿蒙App 架构
人工智能·架构·harmonyos
新小梦9 小时前
DevEco Studio修改HarmonyOS为OpenHarmony
harmonyos
IntMainJhy10 小时前
Flutter 三方库 shimmer 的鸿蒙化适配与实战指南
flutter·华为·harmonyos
IntMainJhy11 小时前
Flutter 三方库 flutter_slidable 的鸿蒙化适配与实战指南
flutter·华为·harmonyos
小羊子说11 小时前
Android ANR 原理浅析
android·性能优化·车载系统