private static String getVersionCode(Context context, String packageName) {
        try {
            return String.valueOf(
                    context.getPackageManager().getPackageInfo(packageName, 0).versionCode);
        } catch (NameNotFoundException e) {
            XLog.e(TAG, "Package not found. could not get version code.");
            return "";
        }
    }
Get version code for the application package name.

@param context
@param packageName application package name
@return the version code or empty string if package not found
android/android_framework/base/src/main/java/com/google/android/vending/licensing/LicenseChecker.java