فهرست منبع

<开机增加launch版本检查>

weizhengliang 4 سال پیش
والد
کامیت
b9c4ad7bd2
3فایلهای تغییر یافته به همراه106 افزوده شده و 1 حذف شده
  1. 1 1
      app/build.gradle
  2. BIN
      app/src/main/assets/launch.apk
  3. 105 0
      app/src/main/java/com/wdkl/callingmainnurse/MyApplication.java

+ 1 - 1
app/build.gradle

@@ -24,7 +24,7 @@ android {
         minSdkVersion 21
         targetSdkVersion 26
         versionCode 1
-        versionName "1.68"
+        versionName "1.7"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
         multiDexEnabled true
 

BIN
app/src/main/assets/launch.apk


+ 105 - 0
app/src/main/java/com/wdkl/callingmainnurse/MyApplication.java

@@ -5,19 +5,32 @@ import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.ServiceConnection;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.os.Environment;
 import android.os.IBinder;
+import android.util.Log;
 
 import com.wdkl.callingmainnurse.entity.AllDoctorHostEntity;
 import com.wdkl.callingmainnurse.entity.UdpEntity;
 import com.wdkl.callingmainnurse.service.APPService;
 import com.wdkl.callingmainnurse.service.led.LedManagerUtils;
+import com.wdkl.callingmainnurse.ui.activity.APPUpdateActivity;
+import com.wdkl.callingmainnurse.util.AutoRebootUtil;
+import com.wdkl.callingmainnurse.util.DownloadUtils;
 import com.wdkl.callingmainnurse.util.ScreenExtinguishUtil;
 import com.wdkl.callingmainnurse.util.SpeechUtil;
 import com.wdkl.callingmainnurse.util.UdpHelper;
 import com.wdkl.callingmainnurse.util.anrfcutil.AnrFcExceptionUtil;
+import com.wdkl.callingmainnurse.util.silentupdate.SilentInstall;
+import com.wdkl.callingmainnurse.util.silentupdate.SilentUpdateUtil;
 import com.zhy.http.okhttp.OkHttpUtils;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -79,6 +92,9 @@ public class MyApplication extends Application {
     //全局医生列表
     public static List<AllDoctorHostEntity.DoctorHost> AllDoctorHostList;
 
+    private boolean needCheckLaunch = true;
+    private boolean copyDone = false;
+
     private void initUdp() {
         wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
         helper = new UdpHelper(wifiManager, sAppContext);
@@ -122,6 +138,95 @@ public class MyApplication extends Application {
         SpeechUtil.getInstance().init(getApplicationContext());
 
         LedManagerUtils.getInstance().ledInit(this);
+
+        //检查launch版本
+        if (needCheckLaunch) {
+            checkLaunch();
+        }
+    }
+
+    //检查launch版本
+    private void checkLaunch() {
+        Log.d("wzlll", "start check launch");
+        PackageManager pm = getPackageManager();
+        List<PackageInfo> packageInfo = pm.getInstalledPackages(0);
+        boolean launchExist = false;
+        for (PackageInfo pInfo : packageInfo) {
+            final String launchName = "com.wdkl.launch";
+            String launchVersion = "1.3";
+            if (launchName.equals(pInfo.packageName)) {
+                launchExist = true;
+                Log.d("wzlll", "start check launch app: " + pInfo.versionName);
+                if (!launchVersion.equals(pInfo.versionName)) {
+                    Log.d("wzlll", "need update launch, app name: " + pInfo.packageName + ", app version: " + pInfo.versionName);
+                    updateLaunchApk();
+                }
+            }
+        }
+
+        Log.d("wzlll", "launch app exist: " + launchExist);
+        /*if (!launchExist) {
+            updateLaunchApk();
+        }*/
+    }
+
+    private void updateLaunchApk() {
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                String apkName = "launch.apk";
+                copyAssetsToDst(getApplicationContext(), apkName, Environment.getExternalStorageDirectory().getPath() + "/" + Environment.DIRECTORY_DOWNLOADS);
+                if (copyDone) {
+                    String fileName = Environment.getExternalStorageDirectory().getPath() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + apkName;
+                    //升级
+                    if (Build.VERSION.SDK_INT >= 26) {
+                        //rk3368 8.1
+                        DownloadUtils downloadUtils = new DownloadUtils(getApplicationContext());
+                        if (downloadUtils.silentInstall(fileName)) {
+                            Log.d("wzlll", "install new launch success, reboot...");
+                            AutoRebootUtil.reboot();
+                        } else {
+                            Log.d("wzlll", "install new launch failed...");
+                        }
+                    } else {
+                        //rk3128 7.1
+                        SilentInstall silentInstall = new SilentInstall();
+                        if (silentInstall.install(fileName)) {
+                            Log.d("wzlll", "install new launch success, reboot...");
+                            AutoRebootUtil.reboot();
+                        } else {
+                            Log.d("wzlll", "install new launch failed...");
+                        }
+                    }
+                }
+            }
+        }).start();
+    }
+
+    //拷贝assets下面的文件到sd卡
+    private void copyAssetsToDst(Context context, String fileName, String dstPath) {
+        try {
+            copyDone = false;
+            File file = new File(dstPath);
+            if (!file.exists()) {
+                file.mkdirs();
+            }
+            File outFile = new File(dstPath + "/" + fileName);
+            InputStream is = context.getAssets().open(fileName);
+            FileOutputStream fos = new FileOutputStream(outFile);
+            byte[] buffer = new byte[1024];
+            int byteCount;
+            while ((byteCount = is.read(buffer)) != -1) {
+                fos.write(buffer, 0, byteCount);
+            }
+            fos.flush();
+            is.close();
+            fos.close();
+            copyDone = true;
+        } catch (Exception e) {
+            copyDone = false;
+            e.printStackTrace();
+        }
     }
 
     /**