Get App Version Code
import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; class Main { public static int getAppVersionCode(Context ctx, String pkgName) { try { PackageManager pm = ctx.getPackageManager(); PackageInfo pkgInfo = pm.getPackageInfo(pkgName, 0); return pkgInfo.versionCode; } catch (NameNotFoundException e) { return 0; } } }