How to detect at runtime if app is installed via app appore amazon or google

What is the recommended recommendation for determining at runtime if the app was installed via the Amazon Android App Store or Google Play? I would like to avoid generating separate APKs for each app my apps are available in.

My preferred approach would be to use PackageManger.getInstallerPackageName.

According to the Android API documentation, this is exactly what I'm looking for: Get the package name of the app that installed the package. This determines in which market the package appeared.

Unfortunately, it turned out that apps installed via the App Store (including KF) returned zero, which would only be expected when the user manually installed the APK.

Can anyone please let me know if there is another way to do this.

+3


source to share


1 answer


Apart from the problem in which it returns null, it getInstallerPackageName()

can be changed and made to return inaccurate information.

I have researched this for a long time and the best solution I could come up with was to create a constants file containing this 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;
}

      



Just use AMAZON

instead GOOGLE_PLAY

in this file and create apk once for each app store.

Elsewhere in your code, you can check this using:

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

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

      

+4


source







All Articles