Java tutorial
//package com.java2s; /* * Tint Browser for Android * * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 3 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.util.Log; public class Main { /** * Get the application version code. * @param context The current context. * @return The application version code. */ public static int getApplicationVersionCode(Context context) { int result = -1; try { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); result = info.versionCode; } catch (NameNotFoundException e) { Log.w("ApplicationUtils", "Unable to get application version: " + e.getMessage()); result = -1; } return result; } }