【问题标题】:How to handle Unable to decode stream: java.io.FileNotFoundException: on using FileProvider (No such file or directory)如何处理无法解码流:java.io.FileNotFoundException:使用 FileProvider(没有这样的文件或目录)
【发布时间】:2017-07-29 05:54:07
【问题描述】:

我试图通过摆脱 FileUriExposedException 来支持 Nougat。当我使用 Uri.fromFile(gettheImageFilehere()) 方法时,我成功获得了图像路径 file:///storage/emulated/0/DCIM/Camera/IMG_20170308_171951.jpg强> 当我使用

FileProvider.getUriForFile(HomeView.this, getApplicationContext().getPackageName() + ".provider",
                gettheImageFilehere());

我得到的图像路径为:/external_files/DCIM/Camera/IMG_20170308_171951.jpg

我尝试使用android.os.FileUriExposedException 上提供的实现 这是我的代码在我的 androidmanifest.xml 里面我添加了提供程序:

<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>

然后我在 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>

我对上述的疑惑:

  1. 在某些示例中,我发现他们使用完整路径。即Android/data/com.example.com/files。我不知道它是否与仅将路径作为a相同。希望有人能帮我解决这个问题。

我得到的完整错误是 Unable to decode stream: java.io.FileNotFoundException: /external_files/DCIM/Camera/IMG_20170308_175833.jpg(没有这样的文件或目录)

代码sn -p .java文件为here查看我的实现。

【问题讨论】:

    标签: android android-fileprovider


    【解决方案1】:

    尝试使用 Intent iGallery = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多