1

I have my versionCode and versionName set in my manifest.xml

android:versionCode="2"
android:versionName="Alpha 1.2"

But how do I output this as a string so the user can see what version of the app they have? In my "about" fragment I attempted to use:

android:text="?android:attr/versionName"

but this didnt seem to work. It literally put "?android:attr/versionName" as the output string.

Vishera
  • 127
  • 1
  • 1
  • 8
  • I've tried this but it cannot resolve symbol for PackageManager or getApplicationContext, or any of that. what imports do I need to use PackageManager? – Vishera Nov 22 '14 at 20:33

1 Answers1

2

android:text="?android:attr/versionName"

Pleasae do not write markup/code etc you do not understand in first place. This is not going to do any magic just because you wrote it or deeply hope it to work even especially it makes no sense at all.

Data from Manifest can be obtained by using of PackageManager

PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);

PackageInfo structure holds both versionName and versionCode - See docs here.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • isnt that the point of this site? to seek answers about something we dont understand? what is the imports to use mAppContext, packageInfo and getPackageInfo? – Vishera Nov 22 '14 at 20:42