7

I'm using FileProvider in my app, when I take a picture from the app is stored there. also my app have a different application id for debug and release builds

  • com.rkmax.myapp
  • com.rkmax.myapp.debug

I have defined my file provider like this

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="@string/authority_file_provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>

the value of @string/authority_file_provider will turn into:

  • com.rkmax.myapp.fileprovider
  • com.rkmax.myapp.debug.fileprovider

and my @xml/file_paths is defined like

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path name="my_images" path="Android/data/com.rkmax.myapp/files/Pictures" />
</paths>

if I try to changes to something like Pictures or files/Pictures my app fails

Failed to find configured root that contains/storage/emulated/0/Android/data/com.rkmax.myapp.debug/files/Pictures/20161112_073128-251269360.jpg

How I define a relative path in the file provider paths?

rkmax
  • 17,633
  • 23
  • 91
  • 176

1 Answers1

13

For your particular case, replace:

<external-path name="my_images" path="Android/data/com.rkmax.myapp/files/Pictures" />

with:

<external-files-path name="my_images" path="Pictures" />

This will require 24.0.0 or higher of the support libraries, IIRC.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Same error. After tos of trial error I get this working, replacing the path by `.` – rkmax Nov 12 '16 at 13:12
  • 1
    @rkmax: For the particular file in your question, that should not be necessary AFAIK. There could be other files that you are serving, not in `Pictures/`, for which you would need `.` as the path, though. – CommonsWare Nov 12 '16 at 13:21