项目场景:
版本更新
问题描述:
下载完成之后不弹出安装页面
原因分析:
Android版本适配问题
解决方案:
添加fileprovider并且适配Android7.0以上跳转安装页面的代码
这是fileprovider的添加路径以及代码
<external-path
name="external_storage_root"
path="." />
<files-path path="." name="files_path" />
在清单文件中引用fileprovider
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//兼容7.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(MainActivity.this, “{applicationId}.fileprovider”, new File(outFile));
intent.setDataAndType(contentUri, “application/vnd.android.package-archive”);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
Log.d(“安装apk”, “正常进行安装”);
intent.setDataAndType(Uri.fromFile(new File(outFile)), “application/vnd.android.package-archive”);
}
Log.d(“安装apk”, “跳转安装页面”);
startActivity(intent);
finish();