Click here to Skip to main content
15,881,812 members
Articles / Mobile Apps / Android
Tip/Trick

Get the versionCode and versionName of your Android app

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
23 Nov 2011CPOL 35.8K   5   2
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)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUpdate Pin
Member 1112095018-Apr-15 3:44
Member 1112095018-Apr-15 3:44 
Questionmy problem Pin
reza kia23-Jan-12 4:23
professionalreza kia23-Jan-12 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.