Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to especific path external-path for apps with dynamic applicationId

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?

like image 847
rkmax Avatar asked Nov 12 '16 12:11

rkmax


People also ask

What is appid in Android?

Every Android app has a unique application ID that looks like a Java package name, such as com. example. myapp. This ID uniquely identifies your app on the device and in Google Play Store. Once you publish your app, you should never change the application ID.

How do I use FileProvider on Android?

To make FileProvider work follow these three steps: Define the FileProvider in your AndroidManifest file. Create an XML file that contains all paths that the FileProvider will share with other applications. Bundle a valid URI in the Intent and activate it.


1 Answers

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.

like image 146
CommonsWare Avatar answered Nov 15 '22 13:11

CommonsWare