Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; public class Main { /** * Get give package version code. * * @param context Object of {@link Context}. * @param pkg package name. * @return Package version code. */ public final static int getAppVersionCode(Context context, String pkg) { PackageManager pm = context.getPackageManager(); try { PackageInfo info = pm.getPackageInfo(pkg, 0); return info.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); return 0; } } }