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 int getVersionCode(Context appContext) { try { PackageInfo packInfo = appContext.getPackageManager().getPackageInfo(appContext.getPackageName(), 0); return packInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return 1; } } }