How to get the build/version number of your Android application?

Fahad Ali Shaikh picture Fahad Ali Shaikh · Jan 6, 2011 · Viewed 648.7k times · Source

I need to figure out how to get or make a build number for my Android application. I need the build number to display in the UI.

Do I have to do something with AndroidManifest.xml?

Answer

plus- picture plus- · Jul 6, 2011

Use:

try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    String version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

And you can get the version code by using this

int verCode = pInfo.versionCode;