Java tutorial
//package com.java2s; import android.content.Context; import android.content.pm.PackageManager.NameNotFoundException; public class Main { public static final int INVALID_VERSION_CODE = -1; public static int getVersionCode(Context context) { int versionCode; try { versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { versionCode = INVALID_VERSION_CODE; } return versionCode; } }