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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With