【问题标题】:Getting Caused by: android.os.FileUriExposedException: after performing required steps引起:android.os.FileUriExposedException:执行所需步骤后
【发布时间】:2023-03-17 10:15:01
【问题描述】:

我关注了几篇关于FileUriExposedException 问题以及如何解决它的文章。我关注了其中一个,并进行了关注,但在这一切之后,我仍然收到以下错误消息。

引起:android.os.FileUriExposedException: file:///storage/emulated/0/My_photo_1518346135450 暴露在应用程序之外 通过 ClipData.Item.getUri()

这是我到目前为止所做的

AndroidManifest.xml

   <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">

        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>

    </provider>

provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path path="."   name="app_cam_images" />
</paths>

这就是我在启动相机之前所做的活动。

    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    randomString= String.valueOf(System.currentTimeMillis());
    FILE_NAME= FILE_NAME+randomString;
    File photo = new File(Environment.getExternalStorageDirectory(), FILE_NAME);


    String authorities = getApplicationContext().getPackageName()+ ".fileprovider";
    Uri imageURI= FileProvider.getUriForFile(this, authorities, photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,imageURI);
    startActivityForResult(intent, REQUEST_CODE);

【问题讨论】:

    标签: android performance android-layout android-camera android-fileprovider


    【解决方案1】:

    startActivityForResult 之前使用它,您必须授予读取 URI 的标志..

    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      • 2014-03-06
      • 1970-01-01
      • 2022-08-15
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      相关资源
      最近更新 更多