12

I have app in Google Play, Amazon, Samsung Apps and I plan to upload to other stores. I do not wish to compile separate build for every store. Is there way to detect what store installed app if same app submitted to different stores?

Max
  • 6,286
  • 5
  • 44
  • 86

3 Answers3

16

You'll have to expand this for each additional store, but this should get you started

if (context.getPackageManager().getInstallerPackageName(context.getPackageName()).equals("com.android.vending")
{
//do google things
}
else if (context.getPackageManager().getInstallerPackageName(context.getPackageName()).equals("com.amazon.venezia")
{
//do amazon things
}
Fabian Streitel
  • 2,702
  • 26
  • 36
prestomation
  • 7,225
  • 3
  • 39
  • 37
  • 4
    I have NOT found this to be reliable in the past. I experimented with sending the getInstallerPackageName on installation to my webserver with a popular app uploaded to 6 marketplaces and 41% were not even set – jamesc Aug 13 '13 at 17:14
  • 1
    If using this to redirect a user to a store, use a switch, and default to Google Play Store. – Pierre Jun 19 '19 at 15:57
11

I detect Installer like this inside the MainActivity:

//is installed via amazon, google?
String installerId = null;
try {
    installerId = this.getPackageManager().getInstallerPackageName(this.getPackageName());
} catch (Exception e) {
    //just in case...
}

if ("com.amazon.venezia".equals(installerId)) {
    // amazon 
} else if ("com.android.vending".equals(installerId)) {
    // google
} else {
    // others & unknown ones
}

I have tested this in my last app and it passed app submission in googe play, amazon store and slideme.org store

Update: looks like sometimes there is the installer package name com.google.android.feedback which seems to be related to google store as well, although I have seen in my test app's google analytics that com.android.vending is by far more frequent. So if you want to make this even more precise you should handle this installer package as well. Also note that some markets (like slideme.org) simply don't seem to set a package installer id at all.

See also: Can PackageManager.getInstallerPackageName() tell me that my app was installed from Amazon app store?

Community
  • 1
  • 1
donfuxx
  • 11,277
  • 6
  • 44
  • 76
3

Not unless you make seperate builds. But with a good maven setup/ant script you could easely automate this process.

Warpzit
  • 27,966
  • 19
  • 103
  • 155