9

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.

Community
  • 1
  • 1
Soham
  • 4,940
  • 3
  • 31
  • 48

3 Answers3

5

So here is what i ended up doing:

  • I created two separate content providers for each version (each with a separate authority) and declared them uniquely
  • set their "android:exported" to "true" to enable sharing the content provider data across apps
  • defined a custom permission to each of the content providers (with read+write access) to restrict access to the data
  • for each of the permission definitions, I defined the "android:protectionLevel" attribute to "signature" so that my applications can implicitly and securely communicate with each other
  • in any given version, i then explicitly ask to access the content provider in the other version using the uses-permission android:name="MY_CUSTOM_PERMISSION element

Results:

  • Both the versions can now securely and implicitly access each others content-providers
  • When the paid version is fired up, it silently copies all the data from the free version to the paid one to prepare for seamless use
Soham
  • 4,940
  • 3
  • 31
  • 48
  • I'd like to do something similar, but it is not working. Can you tell me if you signed your two versions with the same key alias, or only with the same key store ? – Tim Autin Aug 24 '15 at 15:24
4

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.

AAP
  • 1,246
  • 12
  • 21
  • wow, very very interesting approach Asim :) Do you share a content provider between the two versions? – Soham Mar 07 '13 at 12:01
  • I do not have a content provider, but you can define a separate authority for the content provider in the respective manifest and "add" both authorities in your CP code in the shared lib – AAP Mar 08 '13 at 15:26
1

Just my thoughts.

Is there really a need to have both the free and the paid version installed in a device? If not, you can simply provide a copy feature from free to paid when a user first launches the paid version. Then user can remove the free version and use the paid version exclusively.

The approach is fine. But I see one problem with it.

What happens when the content providers change over time? Lets say you decide to enhance the content provider with a few more fields. Then user should upgrade both the versions so that data is properly written.

Will both the content providers stay the same over time? What if you decide paid version will have more features, and hence more data is captured.

Gautham
  • 3,418
  • 3
  • 30
  • 41
  • Good point, but I plan to keep the schema for both the databases to be the same, thereby reducing complexity. In that case, either the free version will use a subset of the whole database or the paid version will know what specific data needs to be pulled from the free version. – Soham Mar 07 '13 at 12:00
  • 2 thoughts: if database change over time(both free & paid), pulling(or pushing the data here) sync mechanism has to be compatible with all the future releases. Since user might be using an old version of free but newer version of paid. So is the overhead worth? Next, lets say paid version has location but free version does not. User expects the location to be available for the content in the paid app irrespective of if it was entered via free or paid. But if user sees the content added through free in the paid version, location will not be available. – Gautham Mar 07 '13 at 12:32
  • good point. I am not going to a periodic free to paid sync feature, just a one time bridge between the two like your initial answer. – Soham Mar 08 '13 at 10:13