Przeglądaj źródła

修复Hicar界面展示

chendeben 1 rok temu
rodzic
commit
88373f9de7
1 zmienionych plików z 35 dodań i 30 usunięć
  1. 35 30
      entry/src/main/ets/entryability/EntryAbility.ets

+ 35 - 30
entry/src/main/ets/entryability/EntryAbility.ets

@@ -385,40 +385,45 @@ export default class EntryAbility extends UIAbility {
     hilog.info(0x0000, 'Heanup2', '%{public}s', 'Ability onBackground end');
   }
 
-  getHiCarStatus() {
-    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);
-      }
+    getHiCarStatus(){
+        if (!this.awareness){
+            this.awareness=canIUse("SystemCapability.CarService.DistributedEngine")?smartMobilityCommon.getSmartMobilityAwareness():undefined;
+        }
+        console.log('enter getHiCarStatus,awareness:'+JSON.stringify(this.awareness));
+        if(this.awareness){
+            // this.awareness = smartMobilityCommon.getSmartMobilityAwareness();
+            console.log('enter awareness');
+            // 业务类型
+            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);
+            }
 
-      // 出行连接状态回调函数
-      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);
+            // 出行连接状态回调函数
+            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);
         }
-        this.sendChangeEvent()
-      };
-      // 注册智慧出行连接状态的监听
-      this.awareness.on('smartMobilityStatus', types, callBack);
-    } else {
-      AppStorage.setOrCreate('isHiCarStatus', false);
-    }
 
 
-  }
+
+    }
 
   //发送广播通知更新UI
   sendChangeEvent() {