:::: MENU ::::
Posts tagged with: versionName

Android get versionCode and versionName from your AndroidManifest.xml

Sometimes showing version in your app is a good think, and when you do this a good think is to not have 2 ore more places where wou have to maintain tha app version for every releases.

In your AndroidManifest.xml there is required 2 fields

android:versionCode witch is an int with the app version

android:versionName witch is a string something like 1.0.1 showing app version.

It is recomanded to use them and do not maintain a separate constant for using it in your code. Ok so programmatically you can retrieve this fields from your AndroidManifest.xml like this:

/* Get android:versionName */
String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

/* Get android:versionCode */
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;