一般情况下我们APP版本更新完后,会自动将新下载的安装包替换旧的安装包,安装完毕后就将app关闭了,但是这样子想使用app的话,还要重新手动点开,用户体验上会比较差
,那我们能不能在版本更新完后,给个提示,这样会更友好一些,答案是可以的
效果图:
详见代码:
/**
* 安装APK
*
* @param file
*/
public static void installApk(Context context,File file) {
Intent intent = new Intent();
//执行动作
intent.setAction(Intent.ACTION_VIEW);
//添加FLAG
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//执行的数据类型
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
context.startActivity(intent);
//杀掉本进程
android.os.Process.killProcess(android.os.Process.myPid());
}