Here you can find the source of getAppVersionCode(Context context)
public static int getAppVersionCode(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 int getAppVersionCode(Context context) { PackageInfo appPackage = getAppPackage(context); return appPackage.versionCode; }// ww w . j av a 2 s . c o m public static PackageInfo getAppPackage(Context context) { PackageInfo appPackage = null; try { appPackage = context.getPackageManager().getPackageInfo( context.getPackageName(), 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return appPackage; } }