安装应用

/**

  * 安装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);这一步的话,最后安装好了,点打开,是不会打开新版本应用的。

原文地址:https://www.cnblogs.com/spring87/p/5407720.html