How to know an application is installed from google play or side-load?

AndroidGoogle PlaySideloading

Android Problem Overview


I need to detect my application is installed from google play or other market, how could I get this information?

Android Solutions


Solution 1 - Android

The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.

EDIT: Note @mttmllns' answer below regarding the Amazon app store.

Solution 2 - Android

And FYI apparently the latest version of the Amazon store finally sets PackageManager.getInstallerPackageName() to "com.amazon.venezia" as well to contrast with Google Play's "com.android.vending".

Solution 3 - Android

I use this code to check, if a build was downloaded from a store or sideloaded:

public static boolean isStoreVersion(Context context) {
    boolean result = false;

    try {
        String installer = context.getPackageManager()
                                    .getInstallerPackageName(context.getPackageName());
        result = !TextUtils.isEmpty(installer);
    } catch (Throwable e) {          
    }

    return result;
}

Kotlin:

  fun isStoreVersion(context: Context) =
    try {
      context.packageManager
        .getInstallerPackageName(context.packageName)
        .isNotEmpty()
    } catch (e: Throwable) {
      false
    }

Solution 4 - Android

If you are looking at identifying & restricting the side-loaded app. Google has come up with the solution to identify the issue.

You can follow as below

Project's build.gradle:

buildscript {
 dependencies {
  classpath 'com.android.tools.build:bundletool:0.9.0'
 }
}

App module's build.gradle:

implementation 'com.google.android.play:core:1.6.1'

Class that extends Application:

public void onCreate() {
if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
    // Skip app initialization.
    return;
}
super.onCreate();
.....

}

With this integration, google will automatically identifies if there are any missing split apks and shows a popup saying "Installation failed" and it also redirects to Play store download screen where user can properly install the app via the Google Play store.

Check this link for more info.

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionttomView Question on Stackoverflow
Solution 1 - AndroidMattCView Answer on Stackoverflow
Solution 2 - AndroidmttmllnsView Answer on Stackoverflow
Solution 3 - AndroidPhilipp E.View Answer on Stackoverflow
Solution 4 - AndroidNaveen T PView Answer on Stackoverflow