android.os.FileUriExposedException 解决方法
来源:互联网 发布:无线网本地网络设置 编辑:程序博客网 时间:2024/05/21 23:38
最近遇到个问题,Android7.0的机子调用Uri.fromFile
报
android.os.FileUriExposedException
google一番后找到了原因是因为项目buildsdk>=24时就会报这个错,stackOverFlower里给出的解决方法有两个:
方法 1
在AndroidManifest.xml里添加<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" ... <application ... <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider> </application></manifest>
在res/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>
然后Uri.fromFile
改为
FileProvider.getUriForFile(context,getPackageName()+ ".provider", file);
方法 2
这个方法的作者说因为用了第一种方法,在某些机器上不起作用,但是他用第二种方法却有效;方法如下:
在appliacation的onCreate方法里添加:
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();StrictMode.setVmPolicy(builder.build());builder.detectFileUriExposure()
这两种方法我都试过,都管用
我的github: https://github.com/a1018875550,欢迎follow;
0 0
- android.os.FileUriExposedException 解决方法
- android.os.FileUriExposedException
- android.os.FileUriExposedException
- Android 7.0 android.os.FileUriExposedException
- Android7.0 android.os.FileUriExposedException
- Android N android.os.FileUriExposedException 注意事项
- android 7.0的android.os.FileUriExposedException: 问题解决
- android webview 遇到android.os.FileUriExposedException错误
- android webview 遇到android.os.FileUriExposedException错误
- Android 7.0 报android.os.FileUriExposedException异常
- 解决Android7.0相机 android.os.FileUriExposedException
- android-解决 Android N 上 报错:android.os.FileUriExposedException
- android-解决 Android N 上 报错:android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 解决 Android N 上 报错:android.os.FileUriExposedException
- Android N共享文件报错:android.os.FileUriExposedException
- 解决 Android N 上 报错:android.os.FileUriExposedException
- 解决 Android N 上 报错:android.os.FileUriExposedException
- 讲一讲 Canvas 究竟是个啥
- 13学生成绩处理
- 【小QのSpringBoot-翻译】Spring Boot官方参考指南-第三部分 使用Spring Boot
- 《亿级流量网站架构核心技术》目录一览
- linux高性能服务器编程之EPOLLONESHOT事件
- android.os.FileUriExposedException 解决方法
- react native 这样理解运行机制
- Android 7.0 安装失败的两个原因
- Android中从一个Activity跳转到另一个Activity经历的生命周期?
- 写一个垃圾桶开关盖子的动画其实很简单
- 第二章 Spring MVC入门 —— 跟开涛学SpringMVC
- 正向代理和反向代理
- JavaEE-Servlet
- mybatis-error