Android系统升级到7.0以上后发现,所有的APP升级,下载完成后不自动跳转到安装界面,找到如下解决办法,完美
1、指定访问的文件的路径
在res下,创建xml文件夹,创建file_paths.xml文件
2、file_paths.xml内容为:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<root-path name="root_path" path="." />
<files-path name="xxxx" path="download/" />
<external-path name="xxxx" path="download/" />
<external-files-path name="xxxx" path="download/" />
</paths>
3.引用指定的路径
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.xxx.xxx.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths />
</provider>
4.编写调起安装页面代码
public void update() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // 7.0+以上版本 Uri apkUri = FileProvider.getUriForFile(ctx, "com.hyjk.hao.fileprovider", new File(savefolder, UPDATE_SAVENAME)); //与manifest中定义的provider中的authorities="com.xxxx.fileprovider"保持一致 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(new File(savefolder, UPDATE_SAVENAME)), "application/vnd.android.package-archive"); } ctx.startActivity(intent); }
这样就完成了,OK。