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

前端 未结 2 1319
心在旅途
心在旅途 2021-01-31 10:37

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

2条回答
  •  一个人的身影
    2021-01-31 11:28

    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");
    }
    

提交回复
热议问题