获取版本号
public static int getVersionCode(Context context) { PackageManager pManager = context.getPackageManager(); PackageInfo packageInfo = null; try { packageInfo = pManager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packageInfo.versionCode; }
获取版本
public static String getVersionName(Context context) { PackageManager pManager = context.getPackageManager(); PackageInfo packageInfo = null; try { packageInfo = pManager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packageInfo.versionName; }
获取Meta-Data
public static String getAppMetaData(Context context, String key) { if (context == null || TextUtils.isEmpty(key)) { return null; } String resultData = null; try { PackageManager packageManager = context.getPackageManager(); if (packageManager != null) { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if (applicationInfo != null) { if (applicationInfo.metaData != null) { resultData = applicationInfo.metaData.getString(key); } } } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return resultData; }