Posts Tagged ‘android’
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); }
Tags: android, java
Posted in Development, How to's | No Comments »