Back to project page base-android-utils.
The source code is released under:
Apache License
If you think the Android project base-android-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * @Title: PackageUtil.java//from w ww . j a v a 2 s . c o m * @Package me.pc.mobile.helper.util * @Description: TODO * @author SilentKnight || happychinapc@gmail.com * @date 2014 2014-11-25 ????10:41:46 * @version V1.0.0 */ package me.pc.mobile.helper.v14.util; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; /** * @author SilentKnight * */ public final class PackageUtil { private PackageUtil() { } public static String getAppVersionName(Context context) { try { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block return null; } } public static int getAppVersionCode(Context context) { try { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block return 0; } } }