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

4

76

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

Jacquesjacquet answered 30/5, 2012 at 2:58 Comment(1)
Google has come up with new Sideload Prevention API: developer.android.com/guide/app-bundle/sideload-check?hl=en-419Spannew
C
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.

Cristen answered 30/5, 2012 at 3:3 Comment(7)
@AbhishekB what version of Android are you on? Are you in an emulator?Cristen
@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.Cristen
The getinstallerPackageName link is returning a server error. So link appears to be down.Alrick
we can set installer package name via adb. is there any other api by which we can check that app is installed via playstore.Bartel
@Cristen I have same app installed in Baidu Store in China and Playstore. How to identify in this situation since package name is same.Substantial
Google has come up with new Sideload Prevention API: developer.android.com/guide/app-bundle/sideload-check?hl=en-419Spannew
How to know that the app is installed from the Huawei store?Truancy
P
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".

Puton answered 31/5, 2013 at 17:43 Comment(5)
Cannot make a static reference to the non-static method getInstallerPackageName(String) from the type PackageManagerOrmiston
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.Aggrieve
getInstallerPackageName() method returns correct value on Redmi Note 3 but returns null in HTC. Is this device dependant ?Substantial
If App is Pre installed in device lets say Camera, Calculator and other system app. You will get null value.Estradiol
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.Assiduity
C
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
    }
Casing answered 23/7, 2014 at 9:15 Comment(5)
how do we test this without really push a app to google play for testing?Chessy
I don't think it would be possible. You could use a private beta though.Casing
this might be useful medium.com/@pixplicity/…Ella
Kotlin version should end with isNotEmpty()Jess
May not be a robust solution. See https://mcmap.net/q/261366/-is-it-ok-to-check-legality-of-installing-paid-android-app-by-checking-getinstallerpackagenameJess
I
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.

Incoercible answered 25/6, 2019 at 5:17 Comment(4)
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 ?Ella
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.Goodden
@Naveen T P Hi how can I test this if this actually works? It lets me install the app through android studio.Shortwinded
This is not available anymore. Google has removed those APIs. Check this: #60524790Tso

© 2022 - 2024 — McMap. All rights reserved.