Get android:versionName manifest element in code

jennifer picture jennifer · Feb 10, 2011 · Viewed 31.5k times · Source

I want to know how to parse the AndroidManifest.xml file in order to get the Application Version Number through code. android:versionName

Answer

Vikas Patidar picture Vikas Patidar · Feb 10, 2011

No need to parse the AndroidManifest.xml file for this.

You can get this by using:

try
{
    String app_ver = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
}
catch (NameNotFoundException e)
{
    Log.e(tag, e.getMessage());
}

Use this inside your onCreate() method.