Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static String getVersionCode(Context context, int type) { try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (type == 1) { return String.valueOf(pi.versionCode); } else { return pi.versionName; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return null; } } }