Skip to content

Instantly share code, notes, and snippets.

@Atrix1987
Created December 30, 2016 09:39
Show Gist options
  • Save Atrix1987/7618d1ac61ab3b3bdc328bc7425a0e72 to your computer and use it in GitHub Desktop.
Save Atrix1987/7618d1ac61ab3b3bdc328bc7425a0e72 to your computer and use it in GitHub Desktop.
Android: Get the app installer package name
private static final String UNKNOWN_VALUE = "unknown";
/**
* Get Installer Id for the app
*
* @param context An instance of the application {@link Context}
* @return The installer Id of the installer for the app
*/
public static String getInstallSource(Context context) {
try {
PackageManager pm = context.getPackageManager();
String installerId = pm.getInstallerPackageName(context.getPackageName());
return TextUtils.isEmpty(installerId) ? UNKNOWN_VALUE : installerId;
} catch (Throwable e) {
//intentionally kept empty
}
return UNKNOWN_VALUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment