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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-12 23:12:21