|
|
@@ -38,7 +38,8 @@ import { display } from '@kit.ArkUI';
|
|
|
export default class EntryAbility extends UIAbility {
|
|
|
// UI上下文对象,用于获取窗口信息
|
|
|
private uiContext?: UIContext;
|
|
|
- private awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
|
|
|
+ // private awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
|
|
|
+ private awareness: smartMobilityCommon.SmartMobilityAwareness|undefined = canIUse("SystemCapability.SmartOptimizer.SmartMobility")?smartMobilityCommon.getSmartMobilityAwareness():undefined;
|
|
|
|
|
|
/**
|
|
|
* 窗口尺寸变化回调函数
|
|
|
@@ -163,14 +164,17 @@ export default class EntryAbility extends UIAbility {
|
|
|
|
|
|
onDestroy() {
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
|
|
- let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
|
|
|
- // 出行连接状态回调函数
|
|
|
- const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
|
|
|
- hilog.info(0x0000, 'Received smart mobility info: ', JSON.stringify(info));
|
|
|
- };
|
|
|
- // 解注册智慧出行连接状态的监听 示例2
|
|
|
- this.awareness.off('smartMobilityStatus', types, callBack);
|
|
|
- }
|
|
|
+ if(this.awareness){
|
|
|
+ let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
|
|
|
+ // 出行连接状态回调函数
|
|
|
+ const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
|
|
|
+ hilog.info(0x0000, 'Received smart mobility info: ', JSON.stringify(info));
|
|
|
+ };
|
|
|
+ // 解注册智慧出行连接状态的监听 示例2
|
|
|
+ this.awareness.off('smartMobilityStatus', types, callBack);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
onWindowStageCreate(windowStage: window.WindowStage) {
|
|
|
// Main window is created, set main page for this ability
|
|
|
@@ -274,32 +278,37 @@ export default class EntryAbility extends UIAbility {
|
|
|
|
|
|
|
|
|
getHiCarStatus(){
|
|
|
- this.awareness = smartMobilityCommon.getSmartMobilityAwareness();
|
|
|
+ if(this.awareness){
|
|
|
+ // this.awareness = smartMobilityCommon.getSmartMobilityAwareness();
|
|
|
|
|
|
- // 业务类型
|
|
|
- let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.HICAR];
|
|
|
- // 获取出行业务连接状态
|
|
|
- let info = this.awareness.getSmartMobilityStatus(types[0]);
|
|
|
-
|
|
|
- hilog.info(0x0000, 'getHiCarStatus info: ', JSON.stringify(info));
|
|
|
- if(info&&info.status==1){
|
|
|
- AppStorage.setOrCreate('isHiCarStatus', true);
|
|
|
- }else{
|
|
|
- AppStorage.setOrCreate('isHiCarStatus', false);
|
|
|
- }
|
|
|
+ // 业务类型
|
|
|
+ let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.HICAR];
|
|
|
+ // 获取出行业务连接状态
|
|
|
+ let info = this.awareness.getSmartMobilityStatus(types[0]);
|
|
|
|
|
|
- // 出行连接状态回调函数
|
|
|
- const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
|
|
|
- hilog.info(0x0000, 'getHiCarStatus Received smart mobility info: ', JSON.stringify(info));
|
|
|
+ hilog.info(0x0000, 'getHiCarStatus info: ', JSON.stringify(info));
|
|
|
if(info&&info.status==1){
|
|
|
AppStorage.setOrCreate('isHiCarStatus', true);
|
|
|
}else{
|
|
|
AppStorage.setOrCreate('isHiCarStatus', false);
|
|
|
}
|
|
|
- this.sendChangeEvent()
|
|
|
- };
|
|
|
- // 注册智慧出行连接状态的监听
|
|
|
- this.awareness.on('smartMobilityStatus', types, callBack);
|
|
|
+
|
|
|
+ // 出行连接状态回调函数
|
|
|
+ const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
|
|
|
+ hilog.info(0x0000, 'getHiCarStatus Received smart mobility info: ', JSON.stringify(info));
|
|
|
+ if(info&&info.status==1){
|
|
|
+ AppStorage.setOrCreate('isHiCarStatus', true);
|
|
|
+ }else{
|
|
|
+ AppStorage.setOrCreate('isHiCarStatus', false);
|
|
|
+ }
|
|
|
+ this.sendChangeEvent()
|
|
|
+ };
|
|
|
+ // 注册智慧出行连接状态的监听
|
|
|
+ this.awareness.on('smartMobilityStatus', types, callBack);
|
|
|
+ }else{
|
|
|
+ AppStorage.setOrCreate('isHiCarStatus', false);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|