Here you can find the source of getVersion(Context context)
private static String getVersion(Context context)
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; public class Main { private static String getVersion(Context context) { String version = null;/*from ww w .ja va2 s . c om*/ try { PackageInfo pInfo = context.getPackageManager().getPackageInfo( context.getPackageName(), PackageManager.GET_META_DATA); version = pInfo.versionName; } catch (NameNotFoundException e1) { } return version; } }