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(R.id.txtv); txt.setText("Version:" + versionName); }catch (Exception e){ e.printStackTrace(); }
Just create a textview and replace txtv id with its id
Very helpful
Thank you for this article, it was very helpful for me.