Skip to content

Instantly share code, notes, and snippets.

@benloong
Forked from SeanZoR/getVersionCode
Last active August 29, 2015 14:13
Show Gist options
  • Save benloong/3cb0575b4c6d704c47cb to your computer and use it in GitHub Desktop.
Save benloong/3cb0575b4c6d704c47cb to your computer and use it in GitHub Desktop.
public static int getVersionCode(Context ctx) {
int versionCode = 0;
try {
PackageInfo pInfo = ctx.getPackageManager().getPackageInfo(
ctx.getPackageName(), 0);
versionCode = pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionCode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment