Check if the installation source is from the play store

Asked

Viewed 133 times

2

Hi, I was thinking of doing a version PRO(unannounced) from my Android App, only I would like to know how the source check works, whether it was installed by the play store or the user under the apk and installed, then in case there was a message: You didn’t buy the App.

Can someone explain to me how this process works?

  • 3

    You can use the method getInstallerPackageName class PackageManager to find out if it came from the play store, you have to check the package for this.

  • Thanks, that’s what I wanted to know and I’ll study about.

  • 1

    @Now I’m the one who asks: why don’t you put an answer?

2 answers

2

You can use the method String getInstallerPackageName(String packageName) class PackageManager it will return the package name corresponding to the installation package from the play store, you just need to pass the current package from your application to it and do the verification.

See a short example of how to implement and use the method getInstallerPackageName down below:

public boolean isInstalledFromMarket(String pkgName)
        throws NameNotFoundException { 
    String installerPkg = pkgMngr.getInstallerPackageName(pkgName);
    boolean installedFromMarket = "com.google.android.feedback".equals(installerPkg);
    return installedFromMarket;
}

The variable pkgMngr is an instance of the class PackageManager, as said above, and she is needed.

Sources:
Documentation of the getInstallerPackageName method
Example of the implementation of the getInstallerPackageName method.

  • Thanks for the example!

0

If you’re from Google Play the Packagemanager.getInstallerPackageName() method should return "com.android.vending". Take a look at this one link

But I think you will also have to see if the app has been purchased. How to Secure my app Against piracy

  • Grateful for the response!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.