Share ContentProvider content, but unique content structures

I have a shared library that provides a shared data storage library through ContentProvider. Individual applications then reference the library, but have their own unique data store (i.e., the database schema is shared, but each application has its own database).

My problem is that when I had two applications installed at the same time, I had a conflict because the powers were the same. Therefore, I need to have unique content for each application, but I can’t find a good way to link to a unique authority in the code (setting the manifest is not a problem). I use static CONTENT_URI in each of my types, as recommended, but they should return a different value for each application (referring to the permissions of the application). I'm afraid I need to turn everything into non-static accessors, but I really don't want to do this. Is there any other way that I skip; maybe something that I can set in the manifest?

+2
source share
1 answer

You will need to get ProviderInfo for the provider with PackageManager.getProviderInfo (). The name ComponentName can be created from the Context in which the provider is located and its class. ProviderInfo.authority provides authority. (If there are multiple permissions, these are all packages on this line as a comma-separated list.)

+3
source

Source: https://habr.com/ru/post/1265373/


All Articles