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

后端 未结 1 680
无人及你
无人及你 2021-02-15 11:34

There are many similar Stackoverflow questions.

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

相关标签:
1条回答
  • 2021-02-15 12:24

    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
    
    0 讨论(0)
提交回复
热议问题