自学内容网 自学内容网

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

原文地址:https://blog.csdn.net/m0_70748845/article/details/142577537

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!