I've been playing around with android.R.attr.versionName, which I first saw on this question. This claims to show the version of the app, but I've tried a couple of things that just don't seem to work:
View as a TextView, just shows number:
<TextView ...
android:text="?android:attr/versionName"/>
Get as a string, returns a null pointer exception:
TypedValue value=new TypedValue();
getActivity().getTheme().resolveAttribute(android.R.attr.versionName,value,true);
String version=value.coerceToString().toString();
Any other thoughts? It seems rather useless if there isn't a way to get to the version from either code or XML.
I do know that there are other ways to get the version name, and I'm not interested in them, I'm just curious about this specific variable, and what it's use is.
but I've tried a couple of things that just don't seem to work
I would not expect either of those two to work. A View
is not a manifest file. A layout is not a manifest file.
It seems rather useless if there isn't a way to get to the version from either code or XML.
It is simply not used for processing views. Few things in android.R.attr
pertain to views. At most, this value might be used when Android internally parses the manifest. My guess is that it is in android.R.attr
as a side-effect of some other metadata declaration, as a quick casual search of the Android source code did not turn up a match.