适用于CACHE DIR的Android FileProvider:无法找到包含的已配置根目录

Pra*_*ani 15 android caching android-fileprovider android-7.0-nougat android-7.1-nougat

我找到了很多与FileProvider相关的链接,但我找不到缓存目录的解决方案

java.lang.IllegalArgumentException:无法找到包含的已配置根目录 /data/data/pkg name/cache/1487876607264.png

我想将它用于CACHE DIRECTORY,我如何在提供者中提供路径.

<paths>
    <external-path name="external_files" path="."  />
</paths>
Run Code Online (Sandbox Code Playgroud)

我用它作为:

File file = new File(context.getCacheDir(), System.currentTimeMillis() + ".png");

Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
Run Code Online (Sandbox Code Playgroud)

如果我提供应用程序文件夹路径,但它不能使用缓存目录,它的工作正常.

任何帮助?

Com*_*are 37

使用<cache-path>,而不是<external-path>.请参阅文档.