简体   繁体   中英

How to prevent android app being downloaded outside google play

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?

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:

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM