Is there a way for my app to know the android:versionCode from AndroidManifest.xml or do I have to create a separate constant in one of my classes?
A:
Yes, you can access this information via PackageManager.getPackageInfo
Also, see details about versioning in the documentation
uthark
2010-10-06 16:33:09
+4
A:
I put this in my subclassed android.app.Application but you can use it anywhere you have a context. Just change getPackageManager() to context.getPackageManager().
public int getVersion() {
int v = 0;
try {
v = getPackageManager().getPackageInfo(getApplicationInfo().packageName, 0).versionCode;
} catch (NameNotFoundException e) {
// Huh? Really?
}
return v;
}
Jere.Jones
2010-10-06 16:35:04
Works perfectly! Thanks!
cjavapro
2010-10-06 16:47:32