<span style="font-size:18px;">/** * 获取本地软件版本 */ public static int getLocalVersion(Context ctx) { int localVersion = 0; try { PackageInfo packageInfo = ctx.getApplicationContext() .getPackageManager() .getPackageInfo(ctx.getPackageName(), 0); localVersion = packageInfo.versionCode; LogUtil.d("TAG", "本软件的版本。。" + localVersion); } catch (NameNotFoundException e) { e.printStackTrace(); } return localVersion; } /** * 获取本地软件版本名称 */ public static String getLocalVersionName(Context ctx) { String localVersion = ""; try { PackageInfo packageInfo = ctx.getApplicationContext() .getPackageManager() .getPackageInfo(ctx.getPackageName(), 0); localVersion = packageInfo.versionName; LogUtil.d("TAG", "本软件的版本。。" + localVersion); } catch (NameNotFoundException e) { e.printStackTrace(); } return localVersion; }</span>
原文地址:http://blog.csdn.net/xiaoyi_tdcq/article/details/42060589