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!
Now I'm laughing at version changes!