public static String getVersionName ( Context context ) { try { PackageManager manager = context . getPackageManager ( ) ; PackageInfo info = manager . getPackageInfo ( context . getPackageName ( ) , 0 ) ; return info . versionName ; } catch ( NameNotFoundException e ) { throw new IllegalStateException ( "no such package installed on the device: " , e ) ; } }
Read version name from the manifest of the context .