TamarG
TamarG

Reputation: 3570

Check if paid app was installed

I've created an android application, and also a paid key-application that can open some features in the regular application. I tried to use this code to check if the paid key is installed:

protected static boolean isProInstalled(Context context) {
    PackageManager manager = context.getPackageManager();
    if (manager.checkSignatures(context.getPackageName(), "com.myapps.appkey")
        == PackageManager.SIGNATURE_MATCH) {
        //Pro key installed, and signatures match
        return true;
    }
    return false;
}

It worked on my phone when I installed the two APKs that I exported from Eclipse (I think I exported them. Maybe it was directly with "run"/"debug". I can't remember). But when I uploaded them to Google Play - I got a message from a user that said that he bought the key but the features are still blocked. Is there something I do wrong? What are those signatures anyway? Does it have anything with the alias and keystore when I export the APKs?

Upvotes: 3

Views: 419

Answers (1)

Tenfour04
Tenfour04

Reputation: 93872

The debug key is the default used when you run from the IDE, so while testing, they both were using the same key. But you signed them with different keys for the store, so the signatures won't match.

As @NobuGames mentioned in the comments, at this point since you already published both apps, you can update the free one to check for the key hash of the paid app using a hard-coded string. This theoretically might make it easier for someone to make a premium-unlocked pirate version of your app, although if they are digging into your source code that far, I suspect they would have succeeded anyway. Think of that as a good problem to have (popular enough app for pirates to spend that much time hacking on yours).

Upvotes: 2

Related Questions