I would like to have a way to reference the project's manifest version number in the main part of the code. What I have been doing up until now is to link the version number in a String XML file to the manifest (@string/Version). What I would like to do is to do it the other way around, link a string XML variable to the version in the manifest. The reason? I'd like to only have to change the version number in one location, the manifest file. Is there any way to do this? Thanks!
I believe that was already answered here.
String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
OR
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;