androidcachingandroid-7.0-nougatandroid-fileproviderandroid-7.1-nougat

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


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?


Solution

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