【问题标题】:Android FileProvider for CACHE DIR : Failed to find configured root that containsCACHE DIR 的 Android FileProvider:找不到配置的根目录,其中包含
【发布时间】:2017-07-14 10:27:53
【问题描述】:

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

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

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

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

我把它用作:

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

Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);

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

有什么帮助吗?

【问题讨论】:

    标签: android caching android-7.0-nougat android-fileprovider android-7.1-nougat


    【解决方案1】:

    使用&lt;cache-path&gt;,而不是&lt;external-path&gt;。见the documentation

    【讨论】:

    • 我使用了&lt;cache-path name="my_cache" path="." /&gt;,但仍然`无法找到包含`的配置根目录。我该怎么办?
    • @zihadrizkyef:这意味着您尝试使用的File 不在getCacheDir()getCacheDir() 的子目录中。
    • @CommonsWare 你是一个真正的资产。我觉得我个人欠你 57 杯啤酒。
    【解决方案2】:

    就我而言,我对两条不同的路径使用相同的名称。唯一的工作路径是最后一个。因此,请确保为每个路径指定唯一名称。

    【讨论】:

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