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

相关推荐
程序员黑豆8 小时前
鸿蒙应用开发:@Monitor 装饰器使用教程
前端·harmonyos
熊猫钓鱼>_>9 小时前
ArkTS 装饰器总览:V1 / V2 / 通用装饰器完整学习笔记
笔记·学习·华为·交互·harmonyos·arkts·arkweb
周倦岚10 小时前
ArkTS中的MVC、MVP、MVVM
华为·mvc·harmonyos
echohelloworld1110 小时前
HarmonyOS应用开发实战:猫猫大作战-KV Store 跨端数据同步
harmonyos·鸿蒙
特立独行的猫A10 小时前
Node.js 三方库移植到 OpenHarmony 鸿蒙PC:一篇实操指南
harmonyos
达子66611 小时前
第16章_HarmonyOs开发图解之 音频
华为·音视频·harmonyos
程序员黑豆11 小时前
鸿蒙应用开发之双向绑定实战:从 V1 到 V2 的完整迁移指南
前端·harmonyos
JoyCong199813 小时前
ToDesk鸿蒙移动端更新!四大变化,触控交互深度进化
macos·华为·智能手机·harmonyos·远程工作·远程操作
molihuan14 小时前
最新 spine 4.3 flutter 适配鸿蒙
flutter·动画·harmonyos·鸿蒙·spine
qizayaoshuap14 小时前
# 鸿蒙 HarmonyOS 应用开发实战(第33期)|喝水提醒(Water Reminder)— 可视化水杯与进度动画
华为·harmonyos