Java tutorial
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; public class Main { public static String getVersion(Context context) { String version = null; try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); version = packageInfo.versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return version; } public static PackageInfo getPackageInfo(Context context, String packageName) { PackageInfo packageInfo = null; PackageManager pm = context.getPackageManager(); try { packageInfo = pm.getPackageInfo(packageName, 0); } catch (Exception e) { // TODO: handle exception } return packageInfo; } }