鸿蒙开发(NEXT/API 12)【硬件(注册出行业务事件监听)】车载系统-开发步骤

时间:2024-09-30 21:38:37
  1. 导入Car Kit模块。

    import { smartMobilityCommon } from '@kit.CarKit';
    
  2. 获取SmartMobilityEventAwareness实例。

    let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
    
  3. 注册出行业务事件监听。

// 业务类型
let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
// 出行业务事件回调函数
const callBack = (event: smartMobilityCommon.SmartMobilityEvent) => {
  hilog.info(0x0000, 'Received smart mobility event: ', JSON.stringify(event));
};
// 注册出行业务事件监听
awareness.on('smartMobilityEvent', types, callBack);