代碼如下:
// 開始安裝apk
File apkfile = new File(APK_DOWNLOAD_PATH, APK_DOWNLOAD_NAME);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.fromFile(apkfile),
"application/vnd.android.package-archive");
UpdateManager.this.context.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);這一步的話,最后安裝好了,點打開,是不會打開新版本應用的。