Android7.0 android.os.FileUriExposedException
来源:互联网 发布:怎么使用淘宝钻石展位 编辑:程序博客网 时间:2024/06/06 03:50
导致该问题的只要原因是当buildsdk >=24时,调用Uri.fromFile时会报错,按照如下步骤即可解决:
1、在AndroidManifest.xml中添加如下代码
<provider android:name="android.support.v4.content.FileProvider" android:authorities="包名.fileProvider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /></provider>
2、在res目录下新建一个xml文件夹,并新建一个file_paths的xml文件
<?xml version="1.0" encoding="utf-8"?><paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="files_root" path="Android/data/包名/" /> <external-path name="external_storage_root" path="." /></paths>
3、修改隐式启动Intent的代码
public static void installApp(Context context, File file) { Intent intent = new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", file); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(intent); }
阅读全文
0 0
- Android7.0 android.os.FileUriExposedException
- 解决Android7.0相机 android.os.FileUriExposedException
- Android7.0解决 android.os.FileUriExposedException: file:///storage/emulated/0/
- Android7.0打开本地文件失败 android.os.FileUriExposedException
- 解决android7.0报错:android.os.FileUriExposedException
- Android7.0 发生的android.os.FileUriExposedException错误
- Android7.0android.os.FileUriExposedException: file:///storage/emulated/0/through Intent.getData()
- Android7.0调用系统相机或相册时报错android.os.FileUriExposedException
- 解决Android7.0以上版本升级apk时报android.os.FileUriExposedException的问题
- Android7.0 FileUriExposedException
- FileUriExposedException,android7.0
- Android7.0异常:FileUriExposedException
- 解决Android7.0系统 调用系统相机、系统播放器播放视频、切图兼容问题,报异常android.os.FileUriExposedException
- 解决Android7.0系统 调用系统相机、系统播放器播放视频、切图兼容问题,报异常android.os.FileUriExposedException
- 解决Android7.0系统 调用系统相机、系统播放器播放视频、切图兼容问题,报异常android.os.FileUriExposedException
- Android7.0拍照失败FileUriExposedException
- android.os.FileUriExposedException 解决方法
- android.os.FileUriExposedException
- 疯狂Activiti6连载(12)DMN规范概述
- Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!解决方法
- Eclipse 关闭 updating indexes
- 计数排序java
- Gitblit环境搭建(w7 64位环境)
- Android7.0 android.os.FileUriExposedException
- CC26xx &&CC13xx 多线程
- 轻重链剖分
- android studio使用技巧
- MVP-简单的OkHttp网络请求数据
- poj 2195 Going Home(最小费用流)
- Java之Integer与int类型数据的比较-yellowcong
- 疯狂Spring Cloud连载(16)Hystrix运作流程
- 提防对象切片