Detect if an Android app was downloaded from Google Play vs Amazon vs Other

若如初见. 提交于 2019-12-03 04:24:41

问题


I know this is probably a longshot, but is there any way to detect programatically whether an app was hosted on the Amazon apps store vs on Google Play? I would like to link to the app store the app was downloaded from, and I'd rather not have two different APKs with just this difference if it can be avoided.


回答1:


As of just recently, the Amazon Appstore returns sane values for PackageManager.getInstallerPackageName()

PackageManager pm = context.getPackageManager();
String installerPackageName = pm.getInstallerPackageName(context.getPackageName());

if ("com.android.vending".equals(installerPackageName)) {
    //do google things
} else if ("com.amazon.venezia".equals(installerPackageName)) {
    //do amazon things
}

See here: https://forums.developer.amazon.com/forums/thread.jspa?threadID=680

Examples for rate this app links:

Google Play-

market://details?id=PACKAGANAME

Amazon Store

http://www.amazon.com/gp/mas/dl/android?p=PACKAGENAME

or

amzn://apps/android?p=com.amazon.mp3




回答2:


The easiest way is to use different version codes or names between Amazon and Google Play. Then you can use PackageManager.getPackageInfo to retrieve those values and choose the app store link appropriately from there.

Example: suffix all of your Amazon version names with '.65' i.e., 1.0.65. Then use

public boolean isAmazon(Context context) {
    String versionName = "";
    try {
        versionName = context.getPackageManager().getPackageInfo(
            getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        // Can't find itself...
    }
    return versionName.endsWith(".65");
}


来源:https://stackoverflow.com/questions/15348671/detect-if-an-android-app-was-downloaded-from-google-play-vs-amazon-vs-other

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