开发者社区> 问答> 正文

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();

展开
收起
爱吃鱼的程序员 2020-06-23 01:41:10 388 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    这是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"/>

    再配置个路径<pathsxmlns:android="http://schemas.android.com/apk/res/android"><!--"."表示所有路径--><external-pathname="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以后都需要这么搞文档的权限变的不一样了

    2020-06-23 01:41:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载