|
@@ -8,6 +8,7 @@ import android.content.pm.PackageManager;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Environment;
|
|
|
+import android.support.v4.content.FileProvider;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
@@ -23,11 +24,35 @@ public class AppUpdateHelper {
|
|
|
/**
|
|
|
* 下载的APK文件绝对路径
|
|
|
*/
|
|
|
- public static final String FILE_APK_PATH = Environment.getExternalStorageDirectory() + "/CallingBed2";
|
|
|
+ public static final String FILE_APK_PATH = Environment.getExternalStorageDirectory() + "/CallingDoor";
|
|
|
/**
|
|
|
* 下载的APK文件的文件名
|
|
|
*/
|
|
|
- public static final String FILE_APK_NAME = "CallingBed2APK.apk";
|
|
|
+ public static final String FILE_APK_NAME = "CallingDoorAPK.apk";
|
|
|
+
|
|
|
+ public static void installAPK(Context context) {
|
|
|
+ try {
|
|
|
+ File apkFile = new File(FILE_APK_PATH + "/" + FILE_APK_NAME);
|
|
|
+ if (!apkFile.exists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//安装完成后打开新版本
|
|
|
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // 给目标应用一个临时授权
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0
|
|
|
+ //如果SDK版本>=24,即:Build.VERSION.SDK_INT >= 24,使用FileProvider兼容安装apk
|
|
|
+ String packageName = context.getApplicationContext().getPackageName();
|
|
|
+ String authority = new StringBuilder(packageName).append(".fileprovider").toString();
|
|
|
+ Uri apkUri = FileProvider.getUriForFile(context, authority, apkFile);
|
|
|
+ intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
|
|
+ } else {
|
|
|
+ intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
|
|
|
+ }
|
|
|
+ context.startActivity(intent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public static void updateApp(Context context, UpdateCallBack callBack) {
|
|
|
if (checkApkExit(context)) {
|