Android 7.0 FileUriExposedException 解决
来源:互联网 发布:python win32ui 编辑:程序博客网 时间:2024/05/29 12:39
接着去年的老项目, 因为交接给别的部门了...刚好那边部门的安卓离职了...升级了HTTPS后出现了bug
android.os.FileUriExposedException:
百度后发现.解决办法.同时亲自测试.解决
VmPolicy方式
以上方法固然是推荐使用的,正确的方法。但是我在实际开发中遇到这样的问题。某些应用(此处点名新浪微博)根本无法理解一个指向文件的content://格式的URI。新浪微博接收到这类URI之后,无法加载图片,并会在点击发送微博时崩溃。
另一方面,新浪微博对权限管理的处理采取了一种比较流氓的方式。它会在启动时申请文件读写权限,而如果拒绝该权限的话,居然就直接退出了。我反正是不信什么需要文件权限来放缓存放数据的说辞。放缓存放数据有着一堆不需要权限的目录可用。但是这样一来,我们其实是不需要担心传递一个file://格式URI过去而对方没有权限的。
话说回来,如何解决这一问题呢?我在调研的时候观察到严格模式的一个方法:StrictMode.VmPolicy.Builder.detectFileUriExposure()。顾名思义,调用这个方法就会检测FileUriExposure这件事。这个方法其实从API18就有了,是不是有可能在API24变成了默认选项呢?
在Application.onCreate加入如下代码,置入一个不设防的VmPolicy:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); }
再用旧的方式直接把file://格式的URI发送出去。居然成功了,没有再抛出FileUriExposedException。
阅读全文
0 0
- Android 7.0 FileUriExposedException 解决
- Android 7.0 FileUriExposedException 解决
- Android 7.0 FileUriExposedException 解决
- Android 7.0 FileUriExposedException 解决
- Android 7.0 FileUriExposedException 解决
- Android笔记:Android 7.0 FileUriExposedException 解决
- Android笔记:Android 7.0 FileUriExposedException 解决
- Android笔记:Android 7.0 FileUriExposedException 解决
- 【Android笔记】Android 7.0 FileUriExposedException完美解决
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- Android笔记:解决Android 7.0 FileUriExposedException url异常
- Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException
- Android 7.0 系统相机崩溃解决android.os.FileUriExposedException
- 解决 Android N 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笔记:解决Android 7.0 FileUriExposedException url异常
- (7)spring依赖注入引用其它Bean
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)
- 键盘监听
- LintCode之35 翻转链表
- 预览器编写语言
- Android 7.0 FileUriExposedException 解决
- could not find java se runtime environment
- 实验吧-逆向-该题不简单
- 基于51单片机的计算器写代码遇到的问题及解决办法
- maven常用的中央仓库
- 训练日记
- C6748_PWM
- 测试文章
- Ajax框架之DWR学习(异常处理案例、Bean传递参数、多个Service)-yellowcong