I need to detect my application is installed from google play or other market, how could I get this information?
4 Answers
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.
-
@AbhishekB what version of Android are you on? Are you in an emulator?– MattCDec 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.– MattCDec 17, 2012 at 19:46
-
The getinstallerPackageName link is returning a server error. So link appears to be down. 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.– AnandMar 20, 2018 at 7:41
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".
-
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 ?– AnandApr 16, 2018 at 12:17
-
1If 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. Feb 20, 2019 at 17:14
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
}
-
1how do we test this without really push a app to google play for testing?– bj4947Mar 14, 2018 at 21:55
-
I don't think it would be possible. You could use a private beta though. Mar 15, 2018 at 8:14
-
1
-
1
-
2May not be a robust solution. See stackoverflow.com/a/36299631/1159930 Dec 29, 2019 at 23:53
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.
-
1
-
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.– ZoombieApr 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
-
2This is not available anymore. Google has removed those APIs. Check this: stackoverflow.com/questions/60524290/… Aug 21, 2022 at 17:38