IllegalArgumentException:找不到包含文件路径的已配置根目录

IllegalArgumentException: Failed to find configured root that contains filePath

正在尝试在默认图库应用中打开图片。我无法按照以下步骤解决此问题: 我的文件路径是 /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 中的路径和名称,但没有成功。

替换:

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

与:

<cache-path name="external_files" />

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