views:

260

answers:

4

Let's say for example that I have some Android app that does X. The free version has ads or basic features. I want to have a paid version that removes the ads and adds extra features.

How can I use the paid app as a "license key" to unlock the features in the free app?

So the user would install the free app, then install the paid app to get the extra features, but they would still run the free app (which would now be unlocked). What's the best approach to doing this?

A: 

The route most app developers take on this is to only have one version of the app, but features are enabled (extras) or disabled (ads) based on the presence of the "license key".

edgman
But there are some where simply the presence of the paid app enables the features in the free app.
Bryan Denny
+2  A: 

Provided both apps are from the same developer and signed by the same key, they should be able to share information privately. You could probably use a file (stored with MODE_PRIVATE) , but I think the easiest route is to use SharedPreferences - set a flag in the paid app which will be read by the free one. See http://developer.android.com/guide/topics/data/data-storage.html. No idea if it would be easy to circumvent, especially on rooted devices...

Another way would be to check if the paid app is installed, for example by checking if it accept a specific Intent. See also: http://developer.android.com/resources/articles/can-i-use-this-intent.html; in that example they check if ZXing's barcode scanner is available that way.

In any case, another twist on the idea would be that you could "enable" multiple apps with only one paying, if you so wished. Your paid app would be a simple "support this developer" which would remove ads from all your apps. That's an interesting paying model IMHO.

Joubarc
Bryan, thanks for editing the link in!
Joubarc
+4  A: 

Use PackageManager to ensure your paid package is installed. AND ensure your free package signature matches installed premium package signature. Otherwise somebody would be able to install unsigned app with package name matching your paid package name and unlock premium this way.

This post can help you to find your signature http://stackoverflow.com/questions/986627/detect-if-app-was-downloaded-from-android-market/991120#991120

Fedor
Good point. Thanks for this suggestion.
Bryan Denny
The signature is the most important thing. This will make it impossible to fake the key without the keystore you are signing the app with.
Janusz
A: 

Here is one example of how it can be done:

Intent unlockerAppPresence = null;
APP_LITE_VERSION = false;
try 
{
    unlockerAppPresence = context.getPackageManager().getLaunchIntentForPackage("nameofthepackagethatunlockyoursoftware");
} 
catch (Exception e1) 
{
    APP_LITE_VERSION  = true;
}
if (unlockerAppPresence == null)
    APP_LITE_VERSION  = true;

Combine this with checking of the app's developer signature (as noted by @Fedor) and you should be good to go.

Bryan Denny