Here you can find the source of getAppVersionName(Context context, String defVersion)
public static String getAppVersionName(Context context, String defVersion)
//License from project: Open Source License import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Looper; import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.view.View; import android.view.WindowManager; import android.webkit.URLUtil; public class Main{ static final String TAG = AndroidUtil.class.getSimpleName(); public static String getAppVersionName(Context context, String defVersion) {/* www . j a v a2 s . co m*/ String versionName = defVersion; try { // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionName = pi.versionName; if (versionName == null || versionName.length() <= 0) { return defVersion; } } catch (Exception e) { FrameworkLog.e(TAG, "getAppVersionName Exception: " + e.getMessage()); } return versionName; } }