码迷,mamicode.com
首页 > 移动开发 > 详细

安卓7.0遇到 android.os.FileUriExposedException: file:///storage/emulated.. exposed beyond app through Intent.getData()

时间:2017-03-13 15:10:15      阅读:1597      评论:0      收藏:0      [点我收藏+]

标签:from   目录   rip   logs   encoding   http   ...   dex   resource   

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>

2、在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>

3、修改代码

Uri photoURI = Uri.fromFile(createImageFile());

变成:

Uri photoURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", createImageFile());

 

安卓7.0遇到 android.os.FileUriExposedException: file:///storage/emulated.. exposed beyond app through Intent.getData()

标签:from   目录   rip   logs   encoding   http   ...   dex   resource   

原文地址:http://www.cnblogs.com/netcorner/p/6542373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!