A blog for technology, SEO tips, website development and open source programming.

Display version number on your Android app

2 3,335

Versioning is a critical component of your application upgrade and maintenance strategy.

Versioning is important because:

  • Users need to have specific information about the application version that is installed on their devices and the upgrade versions available for installation.
  • Other applications — including other applications that you publish as a suite — need to query the system for your application’s version, to determine compatibility and identify dependencies.
  • Services through which you will publish your application(s) may also need to query your application for its version, so that they can display the version to users. A publishing service may also need to check the application version to determine compatibility and establish upgrade/downgrade relationships.

This post will demonstrate how to include the version number inside your android application

You will have already noticed that for any update on your code before you publish it on Google Play you need to give different version code and version name inside the Android manifest xml.

 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.androidelements.myProject"
      android:versionCode="1"
      android:versionName="1.0.0">

How you embed version name inside your application?

  • Import the following inside your activity
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
  • Insert a textview with id ver_name inside your layout and use the following code to display the value in a TextView:
String versionName = "";
try {
    final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    versionName = packageInfo.versionName;
} catch (NameNotFoundException e) {
    e.printStackTrace();
}
TextView tv = (TextView) findViewById(R.id.ver_name);
tv.setText(versionName);

References

2 Comments
  1. […] Also Read – How to Display version number on your Android app […]

  2. […] Also Read – How to Display version number on your Android app […]

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More