多个应用程序使用同一个内容提供商 [英] Multiple Apps use same content provider

查看:210
本文介绍了多个应用程序使用同一个内容提供商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一组只在特定的烙印(思迥异的运动队)来区分应用程序;然而,我遇到了一个问题,我使用一个库项目的所有具体品牌的应用程序,并希望使用相同的ContentProvider为所有这些。当我创建了ContentProvider的我宣布管理局在类中的常数(每dev的例子code)和我使用在清单文件中每一个具体的应用程序一样的权限。它看起来像我不能使用相同的权限跨越每一个应用程序,因为我得到试图安装一个应用程序,第二个当此错误(我安装一个品牌ONE仅有罚款,但第二次安装):

I am developing a set of apps that are distinguished only in certain brandings (think different sports teams); however, I am running into a problem where I am using one Library project for all of the specifically branded apps and want to use the same ContentProvider for all of them. When I created the ContentProvider I declared the AUTHORITY as a constant in the class (per the dev example code) and I am using the same authority in every specific app in the manifest files. It looks like I can't use the same authority across every app as I get this error when trying to install a second app (I install one branded one just fine but the second install):

WARN/PackageManager(66): Can't install because provider name com.xxx.Provider (in package com.xxx) is already used by com.zzz

我试了几种方法,但他们都不工作。我还没有完成一个想法,就是建立一个库JAR,只是省略Provider类我已经和在每一个具体的应用程序进行自定义。如何解决这个问题的任何想法,而不诉诸呢?

I've tried several approaches but none of them seem to work. One idea that I haven't done yet, was to create a library jar and just omit the Provider class I have and customize it in each specific app. Any ideas on how to get around this problem without resorting to that?

推荐答案

ContentProviders由权威鉴定,所以它必须是唯一的。我不认为还有周围的任何技巧。

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

此外,还有在Android平台上使用相同的类名两个不同ContentProviders,即使他们有不同的权限,并包含在单独的APK也prevents的错误。请参阅错误这里

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.

希望这有助于。

这篇关于多个应用程序使用同一个内容提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆