Android examples for App:App Information
Obtain application's version code, android:versionCode="1"
import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; public class Main { /**//from w w w.j a v a2 s .c om * Obtain application's version code,<br> * android:versionCode="1" * * @param context * @return */ public static final int obtainVersionCode(Context context) { try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (NameNotFoundException e) { } return 0; } }