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

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

问题描述

我正在开发一组仅在某些品牌上与众不同的应用(想想不同的运动队);但是,我遇到了一个问题,我为所有特定品牌的应用程序使用一个库项目,并希望为所有应用程序使用相同的 ContentProvider.当我创建 ContentProvider 时,我将 AUTHORITY 声明为类中的常量(根据开发示例代码),并且我在清单文件中的每个特定应用程序中使用相同的权限.看起来我无法在每个应用程序中使用相同的权限,因为在尝试安装第二个应用程序时出现此错误(我安装了一个品牌的应用程序很好,但第二个安装):

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 平台中存在一个错误,它也会阻止对两个不同的 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.

希望这会有所帮助.

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

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