Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent android app being downloaded outside google play

Tags:

android

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?

like image 206
Bruno Barros Avatar asked Nov 16 '15 20:11

Bruno Barros


1 Answers

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:

  • https://developer.android.com/google/play/licensing/index.html

  • Setting Up for Licensing

  • Adding Licensing to Your App

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:

  • In-app Billing

  • Implementing In-app Billing

  • Preparing Your In-app Billing Application

Hope it will help

like image 185
piotrek1543 Avatar answered Oct 05 '22 09:10

piotrek1543