74

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

1

4 Answers 4

62

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.

7
  • @AbhishekB what version of Android are you on? Are you in an emulator?
    – MattC
    Dec 14, 2012 at 19:47
  • 3
    @AbhishekB I do not know of a way to find the origination of side-loaded apps. I'm not sure how that would even be tracked since technically it's just an APK file that's loaded onto the device somewhere and then presumably installed via PackageManager.
    – MattC
    Dec 17, 2012 at 19:46
  • The getinstallerPackageName link is returning a server error. So link appears to be down.
    – HasH_BrowN
    Dec 20, 2014 at 8:13
  • we can set installer package name via adb. is there any other api by which we can check that app is installed via playstore. Apr 27, 2017 at 12:26
  • @MattC I have same app installed in Baidu Store in China and Playstore. How to identify in this situation since package name is same.
    – Anand
    Mar 20, 2018 at 7:41
28

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".

5
  • Cannot make a static reference to the non-static method getInstallerPackageName(String) from the type PackageManager Apr 12, 2015 at 5:31
  • Every appstore has their own marketapp on Playstore that in turn installs their apks (packages). The packagemanager getInstaller...() returns the package name of the marketapp which installed a given apk. Eg. com.amazon.venezia is the package name of the amazon marketapp. Pretty clever, because then PlayStore can control which marketapps are trusted. This is designed to eventually prevent ALL untrusted sideloads. Noticing that uptake of new android OS versions is falling dramatically. KitKat might become the defacto standard. Jul 24, 2015 at 22:57
  • getInstallerPackageName() method returns correct value on Redmi Note 3 but returns null in HTC. Is this device dependant ?
    – Anand
    Apr 16, 2018 at 12:17
  • 1
    If App is Pre installed in device lets say Camera, Calculator and other system app. You will get null value. Nov 26, 2018 at 13:20
  • Does anyone know how amazon app store sets the InstallerPackageName to heir package without root permissions? In latest Android versions (nougat/oreo/pie) the conventional way doesn't seem to work and you get the PackageInstaller as the app that installed the app.
    – jdandradex
    Feb 20, 2019 at 17:14
19

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
    }
5
9

Update:

The feature is now obsolete on versions Android 10 or higher.

Installs with missing splits are now blocked on devices which have Play Protect active or run on Android 10.


Follow this on version lower than Android 10

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.

4
  • 1
    I come across about this blog and understood that this is only useful if using split apk feature. And in that this only work if split apk failed to read some depedeny. Is that correct ?
    – CoDe
    Dec 18, 2019 at 9:02
  • This is useful only if your app support App bundle, if you app support traditional single APK delivery from play store. This won't work.
    – Zoombie
    Apr 6, 2020 at 7:47
  • @Naveen T P Hi how can I test this if this actually works? It lets me install the app through android studio. Dec 13, 2020 at 12:39
  • 2
    This is not available anymore. Google has removed those APIs. Check this: stackoverflow.com/questions/60524290/… Aug 21, 2022 at 17:38

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.