zoukankan      html  css  js  c++  java
  • 安卓7.0遇到 android.os.FileUriExposedException: file:///storage/emulated.. exposed beyond app through Intent.getData()

    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());
  • 相关阅读:
    [bzoj1797] [Ahoi2009]Mincut 最小割
    [bzoj3343] 教主的魔法
    [bzoj3702] 二叉树
    [bzoj3809] Gty的二逼妹子序列
    JavaScript的面向对象原理之原型链
    javaScript操作DOM深入理解
    BOM浏览器对象模型
    JavaScript
    DAO模式
    使用ADO.NET访问数据库
  • 原文地址:https://www.cnblogs.com/netcorner/p/6542373.html
Copyright © 2011-2022 走看看