Sfoglia il codice sorgente

hicar的try catch处理

onecold 11 mesi fa
parent
commit
65908949c1

+ 2 - 2
AppScope/app.json5

@@ -2,8 +2,8 @@
   "app": {
     "bundleName": "com.xgplayer.ttmusic.hm",
     "vendor": "example",
-    "versionCode": 20250823,
-    "versionName": "1.5.3",
+    "versionCode": 20250829,
+    "versionName": "1.5.4",
     "icon": "$media:app_icon",
     "label": "$string:app_name",
     "multiAppMode": {

+ 34 - 27
entry/src/main/ets/entryability/EntryAbility.ets

@@ -288,41 +288,48 @@ export default class EntryAbility extends UIAbility {
 
 
     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);
+        try {
+            if (!this.awareness){
+                this.awareness=canIUse("SystemCapability.CarService.DistributedEngine")?smartMobilityCommon.getSmartMobilityAwareness():undefined;
             }
+            console.log('enter getHiCarStatus,awareness:'+JSON.stringify(this.awareness));
+            if(this.awareness){
 
-            // 出行连接状态回调函数
-            const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
-                hilog.info(0x0000, 'getHiCarStatus Received smart mobility info: ', JSON.stringify(info));
+
+                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);
                 }
-                this.sendChangeEvent()
-            };
-            // 注册智慧出行连接状态的监听
-            this.awareness.on('smartMobilityStatus', types, callBack);
-        }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);
+            }
+        }catch (error) {
+            console.error(`Failed to getHiCarStatus: ${error.code}, message: ${error.message}`);
+
+        }
 
 
     }

+ 1 - 1
entry/src/main/ets/pages/ChartsCount.ets

@@ -140,7 +140,7 @@ export struct ChartsCount {
       // 自定义标题栏(Stack实现绝对居中)
       Stack() {
         // 居中标题
-        Text('歌曲统计')
+        Text('次数统计')
           .fontSize(18)
           .fontColor(Color.White)
           .align(Alignment.Center)