android获取当前软件版本号号和版本号名称
<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>
posted on 2017-06-19 18:53 cynchanpin 阅读(24904) 评论(0) 编辑 收藏 举报