Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 869
Alfie Hanssen Avatar asked Oct 25 '13 14:10

Alfie Hanssen


People also ask

How do I see installed apps on Android?

Go to Settings and find the App Management or Apps section, depending on your phone. If you can't locate it, simply perform a quick search within Settings. Once in App Management, tap on See All Apps or App Settings to see the list of apps installed on your device, excluding the system apps.


1 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
like image 152
Offbeatmammal Avatar answered Sep 25 '22 14:09

Offbeatmammal