Display Version in Android Application

Thursday, August 26th, 2010

I was looking for a way to display the Version on the splash screen of my Android app, more specifically, the “versionName” as defined in the application’s AndroidManifest.xml

After A LOT of looking I discovered PackageInfo, which is a Java API to all of the info held in the manifest.

Armed with this information is was easy to produce the following:

private void displayVersionName() {
    String versionName = "";
    PackageInfo packageInfo;
    try {
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    	versionName = "v " + packageInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    TextView tv = (TextView) findViewById(R.id.versionNameTextView);
    tv.setText(versionName);
}

You can leave a response, or trackback from your own site.

Tags: ,
Posted in: Development, How to's



Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>