0

Possible Duplicate

I have a project using 2 different libraries that require ContentProvider:

<provider android:name="android.support.v4.content.FileProvider" 
          android:authorities="${applicationId}.fileprovider" 
          android:exported="false" 
          android:grantUriPermissions="true">
          
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" 
                     android:resource="@xml/file_paths"></meta-data>
</provider>

However, for authorities, one library instructs to use ${applicationId}.fileprovider whilst the other one instructs ${applicationId}.provider.

According to the Android documentation, android:authorities is a list whose values can be separated by a semicolon.

android:authorities="list"

By that logic, doing something like this:

 <provider android:name="android.support.v4.content.FileProvider" 
              android:authorities="${applicationId}.fileprovider;${applicationId}.provider" 
              android:exported="false" 
              android:grantUriPermissions="true">
              
          <meta-data android:name="android.support.FILE_PROVIDER_PATHS" 
                         android:resource="@xml/file_paths"></meta-data>
    </provider>

should work, however, this causes my app to crash with the following error message:

Unable to get provider androidx.core.content.FileProvider: java.lang.IllegalArgumentException: Could not find meta-data for provider with authority my.packagename.fileprovider;my.packagename.provider

I have taken a look at similar questions but the answers do not address this. How do we successfully specify multiple authorities for the same provider?

tendai
  • 1,172
  • 1
  • 11
  • 22
  • Im using libraries, if i specify one authority, the other library won't work hence the need to specify both authorities – tendai Nov 11 '21 at 11:16
  • @blackapps I've edited the question and removed the spaces because even without the spaces, it still does not work – tendai Nov 11 '21 at 11:18

1 Answers1

0

Using FileProvider with multiple authorities i found this possible.

Changed

"${applicationId}.fileprovider"

To

"${applicationId}.fileprovider;${applicationId}.fileproviderxyz"

And all worked as before.

Tested on Android 12 emulator and Android 10 device.

But... that was without changing any code.

As soon as i used the second authority for FileProvider.getUriForFile() there was this IllegalArgumentException.

Instead using multiple authorities for own ContentProvider derived class is ok.

Try: define two providers for FileProvider in manifest file with a single authority each.

blackapps
  • 8,011
  • 2
  • 11
  • 25