【问题标题】:IllegalArgumentException: Failed to find configured root that contains filePathIllegalArgumentException:未能找到包含 filePath 的已配置根
【发布时间】:2017-05-25 15:48:09
【问题描述】:

尝试在默认图库应用中打开图片。我无法按照以下步骤解决此问题: 我的文件路径是/data/data/{applicationName}/cache/file.jpg

意图:

Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(filePath);
     intent.setDataAndType(FileProvider.getUriForFile(this, getApplicationContext()
                            .getPackageName() + ".provider", file),"image/*"); 
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

清单:

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

provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="external_files"
        path="." />
</paths>

我已尝试更改 provider_paths 中的路径和名称,但没有成功。

【问题讨论】:

    标签: android android-fileprovider


    【解决方案1】:

    替换:

    <external-path
        name="external_files"
        path="." />
    

    与:

    <cache-path name="external_files" />
    

    因为您的路径似乎在 getCacheDir()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多