How to get Android App Version Programmatically in Java Android Studio

Here is how to get android app current version code programmatically in java android

Sometimes, you will need get the current version number of your android app programmatically, this can be useful to display the current version of your app to your users because when you update your app, you can just pass the version string to a textview to display it instead of editing your strings.xml file each time when you do an update.

Here is the code

String versionName = BuildConfig.VERSION_NAME;

With this code above, you can now pass the string to a textview

Here is the full code that i use, i just catch the exception, it may not important.

try {

String versionName = BuildConfig.VERSION_NAME;

TextView txt = (TextView) findViewById(;
txt.setText("Version:" + versionName);
}catch (Exception e){

Just create a textview and replace txtv id with its id


Post navigation


This site uses Akismet to reduce spam. Learn how your comment data is processed.