Java tutorial
//package com.java2s; //License from project: Artistic License import android.content.Context; import android.content.pm.PackageManager; public class Main { public static int getVersionCode(Context context) { int versionCode = -1; String pkName = context.getPackageName(); try { versionCode = context.getPackageManager().getPackageInfo(pkName, 0).versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionCode; } public static String getPackageName(Context context) { return context.getPackageName(); } }