Created
December 30, 2016 09:39
-
-
Save Atrix1987/7618d1ac61ab3b3bdc328bc7425a0e72 to your computer and use it in GitHub Desktop.
Android: Get the app installer package name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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