android實現自動升級並安裝開啟
阿新 • • 發佈:2019-01-30
/**
* 安裝APK檔案
*/
private void installApk() {
File apkfile = new File(mSavePath,Constant.appFileName);
if (!apkfile.exists()) {
return;
}
// 通過Intent安裝APK檔案
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.parse("file://" + apkfile.toString()),
"application/vnd.android.package-archive");
mContext.startActivity(i);
android.os.Process.killProcess(android.os.Process.myPid());
}
如果沒有android.os.Process.killProcess(android.os.Process.myPid());最後不會提示完成、開啟。
如果沒有i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);這一步的話,最後安裝好了,點開啟,是不會開啟新版本應用的。
* 安裝APK檔案
*/
private void installApk() {
File apkfile = new File(mSavePath,Constant.appFileName);
if (!apkfile.exists()) {
return;
}
// 通過Intent安裝APK檔案
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.parse("file://" + apkfile.toString()),
"application/vnd.android.package-archive");
mContext.startActivity(i);
android.os.Process.killProcess(android.os.Process.myPid());
}
如果沒有android.os.Process.killProcess(android.os.Process.myPid());最後不會提示完成、開啟。
如果沒有i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);這一步的話,最後安裝好了,點開啟,是不會開啟新版本應用的。