You can use the String getInstallerPackageName(String packageName)
method of class PackageManager
it will return the package name corresponding to the play store installation package, you just need to pass the current package of your application to it and do the verification
See a small example of how to implement and use the getInstallerPackageName
method 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 class PackageManager
, as stated above, and it is required.
Sources: Method documentation getInstallerPackageName
Example of the implementation of the getInstallerPackageName method.