Android examples for App:Package
Get version code from Context
//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 int getVersionCode(Context context) { return getVersionCode(context, context.getPackageName()); }//from ww w . ja va2 s . c om public static int getVersionCode(Context context, String packageName) { int versionCode = 0; try { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = pm.getPackageInfo(packageName, 0); if (null != packageInfo) { versionCode = packageInfo.versionCode; } } catch (NameNotFoundException e) { e.printStackTrace(); } return versionCode; } public static String getPackageName(Context context) { return context.getPackageName(); } }