Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created November 3, 2012 22:05
Show Gist options
  • Save kristopherjohnson/4009032 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/4009032 to your computer and use it in GitHub Desktop.
Get Android app version name and version code
public class AppInfo {
/**
* Get application version string
*
* @param context
* Interface to global information about an application
* environment
* @return String of the form "VV-CC", where VV is the version name and CC
* is the version code (e.g., "1.0.3-25")
*/
public static String getAppVersionNameAndVersionCode(Context context) {
try {
PackageManager pm = context.getPackageManager();
String packageName = context.getPackageName();
PackageInfo info = pm.getPackageInfo(packageName, 0);
String version = info.versionName + "-" + info.versionCode;
return version;
}
catch (Exception ex) {
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment