Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared Content Provider

My application has two versions, a free and pro version and the Content Provider for the app data needs to be shared between the two.

It should be designed keeping the following in mind

  • Data created by any version should be visible in the other version instantly
  • as I understand, both the pro and free versions cannot declare the same content provider in the manifest file
  • Keeping the last point in mind, I need to create separate providers for the free and pro versions

Possible solutions:

  • Create two content providers, one created by the free version, the other by the pro version
  • When the pro version is first launched, if there is any data in the free version, copy that to the pro version
  • Whenever any data is written in the free or pro version, I should check if the other version of Content Provider exists or not, and write to both the Content Providers if they exist
  • Set the android:protectionLevel attribute to "signature" so that both the versions can access both Content Providers

Please let me know if this makes sense and follows best practices with respect to shared content providers. Do share any other ways of doing this.

like image 948
Soham Avatar asked Mar 06 '13 17:03

Soham


People also ask

What is the purpose of the ContentProvider class?

The ContentProvider instance manages access to a structured set of data by handling requests from other applications. All forms of access eventually call ContentResolver , which then calls a concrete method of ContentProvider to get access.

How do I access my content provider?

To access the content, define a content provider URI address. Create a database to store the application data. Implement the six abstract methods of ContentProvider class. Register the content provider in AndroidManifest.

What is a content provider?

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.


1 Answers

I have 3 apps in the market each having a free and a paid version. For a given app, I have 100% code in a Android Shared lib project which is referenced from both the Free and Paid projects. These Free and Paid Android projects are just dummy projects and are only useful for its AndroidManifest.xml.

If you wish to enable/disable some functionality, you can always add the relevant check in the Shared lib based on the package name.

In your code (in the shared lib), you can distinguish between Free or Paid and enable/disable features based on the calling package.

if ("com.example.paid".equals(context.getPackageName()) {
    //enable pro version features
}

Can you not do something similar? This will save you a lot of maintenance overhead.

like image 87
AAP Avatar answered Sep 22 '22 07:09

AAP