12

I'm developing an app for android. Nowadays there is a lot of stores that illegally distribute android paid apps by free. Is there any snippet of code could I write to prevent my android app being downloaded from any other store which is not google play? For example, when the user try to open the app,Showing a message like "You need to buy this app in google play" and then close the app?

Bruno Barros
  • 409
  • 4
  • 14
  • Some code that would check with Google playstore to see whether the app was bought is something that would already really help. –  Aug 14 '16 at 04:31
  • 1
    https://developer.android.com/google/play/licensing/overview.html you can try this – Ufkoku Aug 14 '16 at 08:32
  • 1
    My concern is how to prevent external store other than Google Play which extract my app's APK and distributed it illegally on their website? – user2872856 Aug 15 '16 at 00:47
  • @user2872856: Your only option is to not distribute the app at all. Anyone with an Android device can get at your APK file. Some may choose to redistribute that APK file, even if you would not want that. – CommonsWare Aug 15 '16 at 13:35
  • Under pricing & distribution, there is a marketing op-out option: "do not promote my application except in Google Play and in any Google-owned online or mobile properties". This this work to prevent my app from distributed outside Google Play? – user2872856 Aug 16 '16 at 02:53

1 Answers1

10

Check packageInstallerName

The simplest way to check if your app was downloaded from Google Play is to check if packageInstallerName is empty as in example below:

String installer = getPackageManager().getInstallerPackageName(
        "com.example.myapp");

if (installer == null) {
    // app was illegally downloaded from unknown source. 
} 
else {
    // app was probably installed legally. Hooray!
}

but as we read here: https://stackoverflow.com/a/36299631/4730812

You should not use PackageManager#getInstallerPackageName to check if the app was installed from Google Play or for licensing purposes for the following reasons:

1) The installer packagename can change in the future. For example, the installer package name use to be "com.google.android.feedback" (see [here][2]) and now it is "com.android.vending".

2) Checking the installer packagename for piracy reasons is equivalent to using Base64 to encrypt passwords — it's simply bad practice.

3) Users who legally purchased the app can side-load the APK or restore it from another backup application which doesn't set the correct installer packagename and get a license check error. This will most likely lead to bad reviews.

4) Like you mentioned, pirates can simply set the installer packagename when installing the APK.

So there's only two good ways to prevent Android app being downloaded outside Google Play Store:

Adding licence to your app;

Basically ensures that the application has been bought by the user using device:

enter image description here

Android Reference:

In-app Billing

Make your application free and add built-in purchases.

In-app Billing is a Google Play service that lets you sell digital content from inside your applications. You can use the service to sell a wide range of content, including downloadable content such as media files or photos, virtual content such as game levels or potions, premium services and features, and more. You can use In-app Billing to sell products as:

  • Standard in-app products (one-time billing), or

  • Subscriptions (recurring, automated billing)

When you use the in-app billing service to sell an item, whether it's an in-app product or a subscription, Google Play handles all checkout details so your application never has to directly process any financial transactions. Google Play uses the same checkout backend service as is used for application purchases, so your users experience a consistent and familiar purchase flow.

Any application that you publish through Google Play can implement In-app Billing.

Android Reference:

Hope it will help

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • My concern is how to prevent external store other than Google Play which extract my app's APK and distributed it illegally on their website? – user2872856 Aug 15 '16 at 00:47
  • well, I haven't similar issue yet, but try to use in-app billing, as it works only with Google Play Services, so if your app would be on external site, it wouldn't work properly and it would make many crashes – piotrek1543 Aug 15 '16 at 08:56
  • Does implementing In-App Billing avoid an app downloaded outside Google Play on purchasing of In-App Billing contents ? – Bruno Barros Aug 15 '16 at 23:49
  • As Android Docs, purchasing through In-App Billing works only on Google Plays Store platform, so user who got your app from another store or just apk wouldn't do more as basic app can do. I haven't use it already, but I think if it would be possible to make your app a trial version - you know after a period of time, purchase or delete it as it won't work anymore – piotrek1543 Aug 16 '16 at 06:45