Java tutorial
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.Log; public class Main { public static int getAppVersionCode(Context context) { int versioncode = -1; try { // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versioncode = pi.versionCode; } catch (Exception e) { Log.e("VersionInfo", "Exception", e); } return versioncode; } }