Click here to Skip to main content
Click here to Skip to main content

Tagged as

Get the versionCode and versionName of your Android app

, 23 Nov 2011
Rate this:
Please Sign up or sign in to vote.
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:

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)

Share

About the Author

No Biography provided

Comments and Discussions

 
Questionmy problem Pinmemberreza kia23-Jan-12 4:23 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 23 Nov 2011
Article Copyright 2011 by Jaydeep Jadav
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid