简体   繁体   中英

How to determine at runtime if app is installed via amazon appstore or Google play

What is the recommended best practice for determining at runtime if an app was installed via the Amazon Android Appstore or Google play? I would like to avoid generating separate APKs for each appstore in which my apps are available.

My preferred approach would be to use PackageManger.getInstallerPackageName.

According to the Android API documentation this is exactly what I'm looking for: Retrieve the package name of the application that installed a package. This identifies which market the package came from.

Unfortunately it appears that apps installed via the Amazon Appstore (including KF) return null which is what one would expect only when the user manually installed the APK.

Can somebody let me know if there is another method to do so.

Aside from the problem where it returns null, getInstallerPackageName() can be tampered with and be made to return inaccurate information.

I have looked into this for a long time, and the best solution I could come up with was to have a constants file that contained that information:

public class Constants {

    public static final int GOOGLE_PLAY = 0;
    public static final int AMAZON = 1;
    public static final int BUILT_FOR = GOOGLE_PLAY;
}

Simply use AMAZON instead of GOOGLE_PLAY in this file and build the apk once for each app store.

Elsewhere in your code you can check this by using:

if(Constants.BUILT_FOR == Constants.GOOGLE_PLAY) {
    //Google Play build
}

if(Constants.BUILT_FOR == Constants.AMAZON) {
    //Amazon Build
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM