android 7.0的android.os.FileUriExposedException: 问题解决
2017-10-14 00:07
645 查看
1,先在manifest里面添加红色部分
<application android:name="xxx.xxx.xxx.MyApplication" android:allowBackup="true" android:icon="@mipmap/icona" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:icon"> <provider android:name="android.support.v4.content.FileProvider" android:authorities="这边填写项目包名.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>
2,在res文件夹下新建xml文件夹,在xml文件夹下新建provider_paths.xml然后在里面写上
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="."/> </paths>
3,在写代码的地方添加如下代码,红色部分是添加的代码
private void install(File file) { if (file.exists() && file.length() > 0) {
Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//7.0需要的 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri uriForFile = FileProvider.getUriForFile(this, "项目包名.fileprovider", file); intent = intent.setDataAndType(uriForFile, "application/vnd.android.package-archive"); startActivity(intent); } else {//7.0之下需要的 intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(intent); // finish(); }
} }
相关文章推荐
- android 7.0系统解决拍照的问题android.os.FileUriExposedException:file:///storage/emulated/0/test.txt
- android 7.0系统解决拍照的问题android.os.FileUriExposedException:
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- Android N 7.0中报错:android.os.FileUriExposedException的解决方法
- android 7.0系统打开本地文件的问题android.os.FileUriExposedException:file:///storage/emulated/0/
- android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/Camera/2018012Android 7.0相继崩溃的问题
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException
- Android 7.0的适配问题,android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 【适配整理】Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException
- 【适配整理】Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException
- 解决Android7.0系统 调用系统相机、系统播放器播放视频、切图兼容问题,报异常android.os.FileUriExposedException
- [置顶] 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 解决Android7.0系统 调用系统相机、系统播放器播放视频、切图兼容问题,报异常android.os.FileUriExposedException
- 开发中碰到的问题:Android 7.0 更新APK在安装时的报错 android.os.FileUriExposedException: file:///storage/emulated/0/And
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- Android 7.0 系统相机崩溃解决android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException