Android: Retrieve "version name" from AndroidManifest.xml

0 Comments

I was getting sick of updating the version number on multiple places in my app when releasing updates; "About" screen, "version" variable and then in the Android manifest.

Since the application manifest already had android:versionName, why not use it?

1.try {
2.  MyActivity.GAME_VERSION = getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
3.}
4.catch (NameNotFoundException e) {
5.  // I don't think this ever happens, but let me know if it does!
6.  MyActivity.GAME_VERSION = "0.00";
7.}

So easy, should have looked it up earlier!

122500549513
Now I'm laughing at version changes!

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog