Home » Android » java – Is it possible to reliably detect at runtime which store installed an Android App (Google Play or Amazon Market)?

java – Is it possible to reliably detect at runtime which store installed an Android App (Google Play or Amazon Market)?

Posted by: admin June 15, 2020 Leave a comment

Questions:

There are many similar Stackoverflow questions.

All have answers that suggest using methods like getInstallerPackageName on the PackageManager class.

All also have comments or conflicting answers saying that this is not a reliable approach, suggesting that the only way to reliably check which store installed a given App is to generate two separate binaries, each with a storeFlag set, and upload one binary to Amazon and one to Google Play.

I need to know which store is the App’s installer so that I know which store to communicate with for in-App purchase functionality.

Is the definitive 100% reliable approach to generate two separate binaries? Or is there a 100% reliable code-based runtime approach?

How to&Answers:

two binaries would be the most robust method but checking both the Build.MANUFACTURER and the installerName should get you pretty close (though assuming yo want to check for the Amazon AppStore if the user has installed an old version of the installer on their non-Kindle device and not updated the installerName might report null)

boolean isAmazonDevice = Build.MANUFACTURER.equalsIgnoreCase("amazon");

final Application application = getApplication();
String installerName = application.getPackageManager().getInstallerPackageName(application.getPackageName());
boolean fromAmazonStore = installerName != null && installerName.equalsIgnoreCase("com.amazon.venezia");

and then checking the value for:

isAmazonDevice || fromAmazonStore

should get you what you need for a significant amount of the time.

One scenario where this can confuse matters is if you are sideloading your apk for testing – in that case it wouldn’t have the correct InstallerPackageName. You can fake that by sideloading the apk using:

adb install -i com.amazon.venezia APK_NAME