Android FileProvider for CACHE DIR : Failed to find configured root that contains

Pratik Butani picture Pratik Butani · Feb 23, 2017 · Viewed 7.2k times · Source

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?

Answer

CommonsWare picture CommonsWare · Feb 23, 2017

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