标签:android versioncode versionname
VersionCode升级App版本时用,VersionName显示给用户。
/** * get App versionCode * @param context * @return */ public String getVersionCode(Context context){ PackageManager packageManager=context.getPackageManager(); PackageInfo packageInfo; String versionCode=""; try { packageInfo=packageManager.getPackageInfo(context.getPackageName(),0); versionCode=packageInfo.versionCode+""; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionCode; } /** * get App versionName * @param context * @return */ public String getVersionName(Context context){ PackageManager packageManager=context.getPackageManager(); PackageInfo packageInfo; String versionName=""; try { packageInfo=packageManager.getPackageInfo(context.getPackageName(),0); versionName=packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionName; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
代码获取Android的VersionCode和VersionName信息
标签:android versioncode versionname
原文地址:http://blog.csdn.net/shenyuanqing/article/details/47445959