Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Apps use same content provider

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 

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?

like image 200
dougzor Avatar asked Jul 22 '10 07:07

dougzor


People also ask

How many content providers can an app have?

You can implement as many as you want, as you can see from the documentation here. To register a content provider, you need to add its corresponding <provider> tag in the Android Manifest. In most cases, however, you won't need multiple content providers. One is usually enough, as it can handle multiple tables.

What are the primary use of a content provider?

Content providers can help an application manage access to data stored by itself, stored by other apps, and provide a way to share data with other apps. They encapsulate the data, and provide mechanisms for defining data security.

What is content provider for app?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

What is the main usage of content provider in Android?

The role of the content provider in the android system is like a central repository in which data of the applications are stored, and it facilitates other applications to securely access and modifies that data based on the user requirements.


1 Answers

It's an old question, but I was looking at doing something similar recently. With the Build flavours, its really straight forward now.

Specify the BuildConfigField in the gradle file:

    productFlavors {     free {         applicationId "com.example.free"         buildConfigField 'String', 'AUTHORITY', '"com.example.free.contentprovider"'     }      paid {         applicationId "com.example.paid"         buildConfigField 'String', 'AUTHORITY', '"com.example.paid.contentprovider"'     } 

Specify the provider authority in the manifest:

    <provider         android:name=".ContentProvider"         android:authorities="${applicationId}.contentprovider" /> 

Set the authority in the provider using the BuildConfigField Variable:

    public static final String AUTHORITY = BuildConfig.AUTHORITY 
like image 157
Gaurav Gupta Avatar answered Oct 11 '22 09:10

Gaurav Gupta