Java tutorial
//package com.java2s; import java.util.List; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static int getInstalledAppVersionCodeByPackageName(Context context, String packageName) { PackageManager pm = context.getPackageManager(); List<PackageInfo> packages = pm.getInstalledPackages(0); for (PackageInfo pInfo : packages) { ApplicationInfo info = pInfo.applicationInfo; if (info.packageName.equals(packageName)) { return pInfo.versionCode; } } return -1; } public static List<PackageInfo> getInstalledPackages(Context context) { PackageManager pm = context.getPackageManager(); List<PackageInfo> infos = pm.getInstalledPackages(0); return infos; } }