Search code examples
androidandroid-fileandroid-fileprovider

FileProvider can't retrieve image from storage in Android


I'm trying to retrieve an image from the storage of the app. I have a library that stores an image in file:///data/user/0/com.myapp.android.debug/cache/cropped4227942271894219596.jpg.

I'm trying to retrieve the image by doing the following:

getUriForFile(context, context.applicationInfo.packageName + ".fileprovider", File(imageUri)) but all I get is:

Failed to find configured root that contains /file:/data/user/0/com.myapp.android.debug/cache/cropped4227942271894219596.jpg

My provider_paths.xml is:

<paths> <files-path name="internal_files" path="/cache" /> </paths>

Does somebody know what the problem could be? Thanks in advance!


Solution

  • try adding below code in filepath.xml as cache files needs to be mentioned with cache-path

    <cache-path name="cache_files" path="."  />