Android 日常开发(48)android.os.FileUriExposedException最佳解决办法

前言

我之前在weex的问题合集里面讲过一次这种异常的处理办法不过当时时通过关闭android严苛模式的视角处理的。今天我们来深入sdk,看看这个问题的最佳解决方式

1.我们通过android developer官网搜索android.os.FileUriExposedException这个异常

The exception that is thrown when an application exposes a file:// Uri
to another app.

This exposure is discouraged since the receiving app may not have
access to the shared path. For example, the receiving app may not have
requested the Manifest.permission.READ_EXTERNAL_STORAGE runtime
permission, or the platform may be sharing the Uri across user profile
boundaries.

Instead, apps should use content:// Uris so the platform can extend
temporary permission for the receiving app to access the resource.

This is only thrown for applications targeting Build.VERSION_CODES#N
or higher. Applications targeting earlier SDK versions are allowed to
share file:// Uri, but it’s strongly discouraged.

Android 7.0在文件安全方面提出了更多要求,需要开发者做成额外的配置来明确需求。

2.解决方法
了解FileProvider类的使用

快速解决问题如下:
1.在清单文件里面配置


        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.xxx.fileprovider"
            android:exported="false"</
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值