1.TextView控件
TextView version = findViewById(R.id.version);
2.设置数据
version.setText("版本号 v"+getAppVersionName(getApplicationContext()));
3.获取版本号的方法
/**
* 获取版本号
*
* @return 版本号
*/
public static StringgetAppVersionName(Context context) {
String versionName ="";
try {
PackageManager pm = context.getPackageManager();
PackageInfo p1 = pm.getPackageInfo(context.getPackageName(), 0);
versionName = p1.versionName;
if (TextUtils.isEmpty(versionName) || versionName.length()<=0){
return "";
}
}catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}


网友评论