Java tutorial
//package com.java2s; import android.content.Context; import android.util.Log; public class Main { private static final String TAG = "AppUtils"; public static int getVersionCode(Context context) { try { return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (Exception e) { Log.e(TAG, "Cannot find package and its version info."); return -1; } } }