Android 7.0以上调用相机报错

Android 7.0以上调用相机报错
android.os.FileUriExposedException: file:///storage/emulated/0/file_image.jpg exposed beyond app through ClipData.Item.getUri()错误

在Application 中加入以下代码为什么就好了 ... 查了以下大家都是这样回复 却不知道为什么 有没有大神知道原理呀

        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();

这是fileprivider没适配的问题 7.0以下 可以 Uri.fromFile();去获取 你需要做的是 首先声明一个fileprovider

android:name=".MyFileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/path" />

            再配置个路径  
            <paths xmlns:android="http://schemas.android.com/apk/res/android">
<!--"."表示所有路径-->
<external-path name="path_files" path="."/>


在通过上面的方法调用就好了 只是uri 问题 其他不变

7.0是通过FileProvider来获取URI的 请参考https://blog.csdn.net/liuwei187/article/details/73920750

https://blog.csdn.net/chf1142152101/article/details/54729099

7.0的 权限不一样 你看 楼上的配置就星 7.0 以后 都需要这么搞 文档的权限 变的不一样了