Here you can find the source of getAppVersionCode(Context context)
public static int getAppVersionCode(Context context)
//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 int getAppVersionCode(Context context) { int versionCode = 0; try {//from ww w .j a v a2 s . co m // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionCode = pi.versionCode; } catch (Exception e) { FrameworkLog.e(TAG, "getAppVersionCode Exception: " + e.getMessage()); } return versionCode; } }