Fran Marzoa
Fran Marzoa

Reputation: 4534

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

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 app to both sites and I rather like to know from where the customer has downloaded it within the application. I know, I can deploy different applications to each service, but this adds some maintenance work that could be avoided if there were some manner to solve it just with a conditional within the app using the same package.

Upvotes: 17

Views: 6959

Answers (2)

Levon
Levon

Reputation: 1691

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.

Upvotes: 6

Scott Kennedy
Scott Kennedy

Reputation: 1346

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

Upvotes: 17

Related Questions