30

I found so many links which is related to FileProvider, but I didn't found solution for cache directory

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/pkg name/cache/1487876607264.png

I want to use it for CACHE DIRECTORY, How can I give path in provider.

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

I used it as :

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

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

Its working fine if I give application folder path, but not working with Cache Directory.

Any Help?

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437

2 Answers2

57

Use <cache-path>, not <external-path>. See the documentation.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

In my case I use the same name for two different paths. The only working path is the last one. So make sure to specify unique name for each path.

Harun
  • 667
  • 7
  • 13