Here you can find the source of getAppVersionName(Context context)
public static String getAppVersionName(Context context)
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; public class Main { public static String getAppVersionName(Context context) { PackageInfo appPackage = getAppPackage(context); return appPackage.versionName; }/* ww w. java 2 s. c om*/ public static PackageInfo getAppPackage(Context context) { PackageInfo appPackage = null; try { appPackage = context.getPackageManager().getPackageInfo( context.getPackageName(), 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return appPackage; } }