Browse Source

2.8.2 修复断网重连导致重新进入小程序

xulh 6 months ago
parent
commit
cfa5419309
2 changed files with 54 additions and 3 deletions
  1. 52 1
      app/src/main/java/com/hh/arome/ui/MainActivity.java
  2. 2 2
      config.gradle

+ 52 - 1
app/src/main/java/com/hh/arome/ui/MainActivity.java

@@ -21,9 +21,11 @@ import com.alipay.arome.aromecli.AromeServiceInvoker;
 import com.alipay.arome.aromecli.AromeServiceTask;
 import com.alipay.arome.aromecli.requst.AromeActivateRequest;
 import com.alipay.arome.aromecli.requst.AromeExitAppRequest;
+import com.alipay.arome.aromecli.requst.AromeGetAppStatusRequest;
 import com.alipay.arome.aromecli.requst.AromeLaunchAppRequest;
 import com.alipay.arome.aromecli.requst.AromeSendEventRequest;
 import com.alipay.arome.aromecli.response.AromeExitAppResponse;
+import com.alipay.arome.aromecli.response.AromeGetAppStatusResponse;
 import com.alipay.arome.aromecli.response.AromeResponse;
 import com.alipay.iot.bpaas.api.BPaaSApi;
 import com.alipay.iot.bpaas.api.BPaaSInitCallback;
@@ -1427,6 +1429,44 @@ public class MainActivity extends BaseHHActivity implements DeviceConfigContract
     }
 
 
+
+    // 小程序状态
+    boolean appletRunnning;
+    boolean appleForeground;
+
+
+    /**
+     * 获取小程序运行的状态
+     */
+    public void getAppletStatus(){
+
+        AromeGetAppStatusRequest request = new AromeGetAppStatusRequest();
+        request.appId = appletId;
+        AromeServiceInvoker.invoke(request, new AromeServiceTask.Callback<AromeGetAppStatusResponse>() {
+            @Override
+            public void onCallback(final AromeGetAppStatusResponse response) {
+
+                AppLogUtils.e("小程序运行状态response:"+response.toString());
+
+                if(response!=null){
+                    // 小程序是否正在运行 true/false
+                    Boolean isRunnning = response.isRunnning;
+                    // 小程序是否在前台 true/false
+                    Boolean isForeground = response.isForeground;
+
+
+                    appletRunnning = isRunnning;
+                    appleForeground = isForeground;
+
+                }
+
+            }
+        });
+
+    }
+
+
+
     /**
      * 日志统一打印
      * 网络和本地保存日志
@@ -4048,11 +4088,22 @@ public class MainActivity extends BaseHHActivity implements DeviceConfigContract
 
             final DeviceConfigResultBean newResultBean = resultBean;
 
+            // 先获取下小程序状态
+            getAppletStatus();
+
             // 为了身份证初始化成功
             mHandler.postDelayed(new Runnable() {
                 @Override
                 public void run() {
-                    initAndActive(newResultBean);
+
+                    if(appletRunnning&&appleForeground){
+                        // 小程序已经运行
+                        AppLogUtils.e("小程序已经运行,不操作");
+                    }else{
+                        AppLogUtils.e("小程序没有运行,开始启动");
+                        initAndActive(newResultBean);
+                    }
+
                     // 如果未打开,那就是error1, no implement
                 }
             }, 5 * 1000);

+ 2 - 2
config.gradle

@@ -7,8 +7,8 @@ ext {
 //            minSdkVersion    : 24,
             minSdkVersion    : 21,
             targetSdkVersion : 22,
-            versionCode      : 28,
-            versionName      : "2.8.1"
+            versionCode      : 29,
+            versionName      : "2.8.2"
     ]
     //依赖 配置
     dependencies = [