开发者

Need to share ContentProvider code but unique content authorities

开发者 https://www.devze.com 2023-04-02 01:08 出处:网络
I have a common library which provides a common data storage library via a ContentProvider. Individual applications then reference the library, but have their own unique data storage (i.e. the databas

I have a common library which provides a common data storage library via a ContentProvider. Individual applications then reference the library, but have their own unique data storage (i.e. the database schema is shared, but each app has its own database).

My problem is that when I have two apps installed at the same time, I got a conflict because the authority was the same. So I need to have a unique content authority for each app, but can't find a good way of referencing the unique authority in the code (configuring the manifest is not a problem). I use a static CONTENT_URI in each of my types as recommended, but those need to return a different value for each app (referencing the app-specific authority). I'm afraid I need to turn everything into non-static accessors, but I don't really want to do that. Is there some other way that I'm missing; perhaps something that I can 开发者_如何转开发set in the manifest?


You will need to retrieve the ProviderInfo for the provider with PackageManager.getProviderInfo(). The ComponentName can be constructed from the Context the provider is in and its class. ProviderInfo.authority provides the authority. (If there are multiple authorities, these are all package in that string as a comma-separated list.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号