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