Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

Get the versionCode and versionName of your Android app

The following trick tell you How to get the versionCode and versionName of your android app using code
In you AndroidManifest.xml file, you can specify the values of android:versionCode and android:versionName.

versionCode

The versionCode is integer value used to easily differentiate between app versions.

App developers must increment this value when they release updates to their apps in Android Market, so it can determine if users are using an old version of the app, and offer them to update it.

versionName

The versionName is a string containing a regular "release version" as seen in other desktop applications, such as "1.4.5″ or "3.7″.

The versionName is just a "human readable" version code.

Accessing it

Here is how you can access these values in your application code:

Java
PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
int versionNumber = pinfo.versionCode;
String versionName = pinfo.versionName;


This way, you can check which version of your app is being used, if you need to do something spesific with that information. Or you can make a small method that checks for new updates to the app.
Note

You can also access other useful resources this way, for example: packageName and requestedPermissions.

More on android app versioning here, and AndroidManifest i explained in depth here[^].

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)