【发布时间】:2018-01-15 12:03:29
【问题描述】:
我为我的应用实施更新操作。 .apk 文件夹下载 WebService,我手动尝试它可以工作,但下载后在程序上 .apk 文件夹无法启动。我得到错误设备尝试安装它“程序安装已停止”我该如何修复它?。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri apkUri = FileProvider.getUriForFile(updateManager.updateContext, BuildConfig.APPLICATION_ID + ".provider",
new File(Environment.getExternalStorageDirectory() + "/download/" + updateManager.apkOutPath));
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData(apkUri);
intent.setFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
updateManager.updateContext.startActivity(intent);
} else {
try {
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File toInstall = new File(PATH,updateManager.apkOutPath );
Uri apkUri = Uri.fromFile(toInstall);
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(apkUri,
"application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
updateManager.updateContext.startActivity(install);
catch (Exception e){
e.printStackTrace();
}
}
【问题讨论】:
标签: android android-intent android-fileprovider