Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; public class Main { private static PackageManager pm = null; /** * get version code of this app * @param context context * @return version code */ public static int getVersionCode(Context context) { if (pm == null) { pm = context.getPackageManager(); } try { return pm.getPackageInfo(context.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return -1; } }