Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 413
Fahad Ali Shaikh Avatar asked Jan 06 '11 14:01

Fahad Ali Shaikh


People also ask

How do I find the build number?

1 Go to "Settings", then tap "About device" or "About phone". 2 Scroll down, then tap "Build number" seven times. Depending on your device and operating system, you may need to tap "Software information", then tap "Build number" seven times.

What is build version in Android?

Build. VERSION . CODENAME : The current development codename, or the string "REL" if this is a release build. INCREMENTAL : The internal value used by the underlying source control to represent this build. RELEASE : The user-visible version string.


2 Answers

If you're using the Gradle plugin/Android Studio, as of version 0.7.0, version code and version name are available statically in BuildConfig. Make sure you import your app's package, and not another BuildConfig:

import com.yourpackage.BuildConfig; ... int versionCode = BuildConfig.VERSION_CODE; String versionName = BuildConfig.VERSION_NAME; 

No Context object needed!

Also make sure to specify them in your build.gradle file instead of the AndroidManifest.xml.

defaultConfig {     versionCode 1     versionName "1.0" } 
like image 59
Sam Dozor Avatar answered Sep 30 '22 04:09

Sam Dozor


Use:

try {     PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.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; 
like image 34
plus- Avatar answered Sep 30 '22 02:09

plus-