Use:
(使用:)
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
And you can get the version code by using this
(您可以使用此代码获取版本代码)
int verCode = pInfo.versionCode;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…