Skip to content

Instantly share code, notes, and snippets.

@ebridges
Last active December 14, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebridges/5070799 to your computer and use it in GitHub Desktop.
Save ebridges/5070799 to your computer and use it in GitHub Desktop.
Get the versionCode & versionName attributes from `AndroidManifest.xml` at runtime
import android.app.Activity;
// http://stackoverflow.com/questions/3874775/detect-my-apps-own-androidversioncode-at-run-time
public class GetVersion {
public static Integer getVersion(Activity activity) {
Integer version = 0;
try {
version = activity.getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
// Todo: handle
}
return version;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment