且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多个应用使用同一个内容提供者

更新时间:2023-11-22 19:46:40

ContentProviders 是由权限标识的,所以它需要是唯一的.我不认为有任何技巧可以解决.

ContentProviders are identified by the authority, so it needs to be unique. I don't think there are any tricks around that.

此外,Android 平台中存在一个错误,它也会阻止对两个不同的 ContentProvider 使用相同的类名,即使它们具有不同的权限并包含在不同的 APK 中.在此处查看错误.

Additionally, there's a bug in the Android platform that also prevents using the same classname for two different ContentProviders, even if they have different authority and are contained in separate APKs. See the bug here.

我为您建议的解决方案是在您的库项目中创建抽象提供者类,然后在每个单独的应用程序中使用唯一的名称对其进行扩展.为了实现这一点,您可能需要创建一个脚本来生成/修改各个清单和 contentprovider 类.

The solution I advise for you is to create the abstract provider class in your library project, and then extend it with a unique name in each of the individual applications. To make this practical you will probably need to create a script to generate/modify the individual manifests and contentprovider classes.

希望这会有所帮助.