app版本更新 下载apk后没有跳转到安装页面
如果遇到这种情况,可以试试下面的两种方法
1.添加请求安装app的权限
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
2.authority不对。请检查AndroidManifest.xml中配置的authorities是否与引用时一致。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.administrator.omplatformengineer.provider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
以下是引用时的代码
Intent intent =new Intent(Intent.ACTION_VIEW);
File apkFile = queryDownloadedApk(downManager,downloadId);
//判断是否是AndroidN以及更高的版本
if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(context,
"com.example.administrator.omplatformengineer.provider",apkFile);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(contentUri,"application/vnd.android.package-archive");
}else{
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(apkFile),"application/vnd.android.package-archive");
}
context.startActivity(intent);
authorities="com.example.administrator.omplatformengineer.provider这里要一致