Is it possible to have my own (exported = false) ContentProvider for a library project that is used by many different applications?
The problem is that even when the CP is not exported, it must have unique privileges. If it is not unique, you cannot install multiple applications with the same library on the same phone (INSTALL_FAILED_CONFLICTING_PROVIDER).
I know that I can use the application identifier to determine the provider in AndroidManifest as follows:
<provider android:authorities="${applicationId}.provider.test" android:name=".storage.db.MyContentProvider" android:exported="false" />
but I canβt find a solution for generating permissions in the code at runtime to properly initialize the UriMatcher.
BuildConfig.APPLICATION_ID returns the ID of the library project, not the application. I could try to extract the package from the application context, but then this is not the best solution if the application uses flavors with different applications.
So my ideas for solving this problem are:
- finding the correct appplicationId in my library code at runtime (also when using flavors with different application identifiers)
- find a way to properly match URIs in my UriMatcher without the knowledge of authority.
source share