How android app can detect what store installed it?

佐手、 提交于 2019-11-29 23:16:13
prestomation

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
}
donfuxx

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?

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!