How to know if an app has been downloaded from Google Play or Amazon?

前端 未结 2 1606
一整个雨季
一整个雨季 2021-02-01 07:18

Is there any way to know if an application has been downloaded from Amazon App Store or Google Play Store? I meant within the app itself, of course.

I have deployed an a

相关标签:
2条回答
  • 2021-02-01 08:00

    In Code:

    final PackageManager packageManager = getPackageManager();
    
    try {
        final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
        if ("com.android.vending".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) {
            // App was installed by Play Store
        }
    } catch (final NameNotFoundException e) {
        e.printStackTrace();
    }
    

    "com.android.vending" tells you it came from the Google Play Store. I'm not sure what the Amazon Appstore is, but it should be easy to test using the above code.

    Via ADB:

    adb shell pm dump "PACKAGE_NAME" | grep "vending"
    

    Example:

    adb shell pm dump "com.android.chrome" | grep "vending"
    
    installerPackageName=com.android.vending
    
    0 讨论(0)
  • 2021-02-01 08:07

    While in most cases you can get the store name by including a check similar to this:

    final PackageManager packageManager = getPackageManager();
    
    try {
        final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
        if ("com.android.vending".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) {
            // App was installed by Play Store
        }  else if ("com.amazon.venezia".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) {
            // App was installed by Amazon Appstore
        } else {
            // App was installed from somewhere else
        }
    } catch (final NameNotFoundException e) {
        e.printStackTrace();
    }
    

    "com.android.vending" is Google Play Store and
    "com.amazon.venezia" is the Amazon Appstore, and
    null when it was sideloaded

    The results could be unreliable however, as for example during beta testing a store might not set this value, and besides it's possible to sideload your app specifying the installer's package name that could be interpreted as a store name:

    adb install -i <INSTALLER_PACKAGE_NAME> <PATH_TO_YOUR_APK>
    

    You might want to consider having different application IDs for different stores, for example "com.example.yourapp" for Google and "com.example.yourapp.amazon" for Amazon -- you can easily set those in your Gradle script.

    0 讨论(0)
提交回复
热议问题