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


Question

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?

1
1182
9/29/2014 2:05:22 PM

Use:

try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(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;
1965
8/30/2018 7:13:43 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon