Shared Content Provider - android

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.

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

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.

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.

Related

Share data between two flavours of same app (for instance free / premium)

Some free applications can often be upgraded to paid premium versions. Is there a known packaging pattern so that the paid app replaces the free apps, and therefore gets all data the free may have stored ?
I understand that since app is identified by its unique fully qualified name this is impossible for an app to see data from another, but I kinda recall already seeing this. Or does it mean that I have to consider the two apps as completely distinct, and foresee an export/import feature mechanism ?
(this question is not related to the actual development of those two flavours, which can be achieved in many ways, but rather to the way app should be packaged)
Is there a known packaging pattern so that the paid app replaces the free apps, and therefore gets all data the free may have stored ?
No, the package names must be unique. Thus, one app does not "replace" another app and gets its data.
Or does it mean that I have to consider the two apps as completely distinct, and foresee an export/import feature mechanism ?
Yes, two apps are distinct. However, they can still exchange data.
These are common methods:
Publish one (free) app which contains all functionality but only has the free functionality enabled by default. Publish an additional (paid) app which serves as an unlocker. Your free app can check if the unlocker is installed and enabled the paid functionality accordingly. It is recommended to check the package signature of the unlocker app, e.g., as described in the answers here.
Similar to above but use in-app purchases in the free app instead of an additional unlocker app.
Publish both a free and paid app as self-contained apps. You can implement a ContentProvider to transfer data from the free to the paid app. Of course you can implement other export/import methods as well. However, using a ContentProvider with permissions makes it easy to automatically and securely copy the data, e.g., when the paid app is started for the first time.

How to manage free and paid versions of an Android project?

I decided to build a paid version of my free Android application.
The paid version has some extra features. How do I manage both versions?
Is it possible to keep them based on the same source code?
If an application requires unique package name, how do I force paid application to replace free version?
What about db, preferences and other privately stored stuff, how to share them without exposing all data to the rest of the world?
Any advice that will help to manage both projects,
but not answers the above questions directly, is appreciated as well.
There are several approaches:
Put the core of your app in a library project, and create two other projects one for the paid, and one for the free version of the app. An upgrade to the paid version means the user has to uninstall the free version, and looses all the data.
This is the "classical" approach.
Let the user make an in-app payment. The user keeps all database and settings, and you have to maintain only one app.
This option requires extra modules to be included in your app, and extra logic.
Make another dummy/empty app, this is a paid app. The existance of this app means the user has a paid version. The user keeps on using the orginal/free app.
You can simply check by using the PackageManager to see if the paid app is downloaded.
The user keeps all database and settings, and you have to maintain only one app. Ok, there are two apps, but the second can be really small and simple.
You don't have to include additional libraries/code to make an in-app payment. You can also have all your apps upgraded to the 'pro' version with one purchase.
I don't know if all users understand this pattern. For the developper, this can be achieved with minimal work, and the users keep all their settings while upgrading.
I think it's possible and recommended to keep them in same source
code. Otherwise you have to support two versions of app instead of
only one.
If you have only one app therefore you have only one package name.
Create a class responsible for app features availability in current license state (free or paid). This class should store information about license state (free, paid, maybe you will deside to add subscription mode in future in which paid version can expire after some period). Features of your app available only in paid verion shoud check current license state. You can also change app GUI depending of license state. For example hide GUI of paid features, show "Buy" button or ads, etc.
And also if you have only one app that can be free or paid you don't have to share any internal app data between paid and free versions.

Android, two apps one database?

We are developing an android app and we want to make two versions, pro and free. The problem is that our apps use a database which we want to be available for both apps.Is it possible?
I mean, the client downloads the free app, and he uses it. Then he decides to buy the pro version, would it be posible to pass the data from free version to pro version?
Thanks
Two different apps wont be sandboxed from each other and can use the same database provided that they are signed with the same private key and have the same sharedUserId. No need to store the database on a shared folder which might cause breach of sensitive data.
Add:
android:sharedUserId="com.yourprogram"
inside manifest tag in your manifest files and sign both apks with same key. For details:
http://developer.android.com/guide/topics/manifest/manifest-element.html
you can use a content provider if you want
http://developer.android.com/guide/topics/providers/content-providers.html

How to share the google android backup between applications?

I've implemented Android backup for my paid-application. I want to build an ad-supported version of the same app, and since they are using the same data I'd prefer to share the android backup between these two apps. How should I do?
EDIT
The refined question is whether it is possible to share the application backups on Google's servers.
My Answer: AFAIK it is not possible because Google will store the backups per package name, which must be unique per application.
Original Answer
I'm still not sure why you want to access the same data from both apps. Yes I understanding the upgrade path, but why not just copy the data over when the user gets the ad free one?
Anyway, your implementation of the BackupProvider will have to be responsible for managing the shared data. Now since you will have 2 versions of the provider (free + paid) they need to ensure they don't overwrite each other in the shared location (like the sdcard).
But even if you follow this approach Google is still going to maintain 2 separate copies of your users data, one per application (AFAIK this is determined by the package name of the app which must be unique)

Demo and paid application - how to implement?

I have nearly completed my application and about to upload it into Android Appstore. I need to divide demo and paid versions - one is free with limited capabilities, another one - paid with full functionality. The question is: how to implement it - the only idea which I have in my mind is following:
Upload 2 independent applications placed on different packages. But in this case there's one obstacle: let say user installed demo application packaged as my.foo.demo then user decided to buy full version which will be installed in package my.foo.paid. In this case I need to provide user with ability to transfer user files/data/preferences from package my.foo.demo to my.foo.paid. Wow, but it's not very simple task (keeping in mind Android's security model)
Probably there's another approach? Any ideas?
The easiest way would be to upload two independent APKs. There is a way to have a user download a free version, and then download a "key" application that unlocks the paid functionality. That can lead to lots of user confusion since sometimes they will download the "key" application and not the base application. So if you can upload two different versions, that will eliminate that hassle (but means you have to maintain two versions).
So now to answer your question about sharing the data. The simplest way would be to have a content provider for your data and just export that to the paid version. Alternatively, you can look into the sharedUserId attribute in the application's manifest. This will allow you to run in the same process and access the same files.

Categories

Resources