android7.0在拍照的时候遇到android.os.FileUriExposedException: file:///storage/emulated.. exposed beyond app through Intent.getUrl()
三步搞定:
1、清单文件中加:
<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/paths"/>
</provider>
在res文件中新建xml文件夹,在xml文件夹中新建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 photoURI = Uri.fromFile(file);
换成:
Uri photoURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);