Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static int getAppVersionCode(Context context) { PackageInfo packageInfo = getPackageInfo(context); if (packageInfo != null) { return packageInfo.versionCode; } return -1; } public static PackageInfo getPackageInfo(Context context) { try { return context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; } }