Is there a simple way to find the current version of my application from within it? I would like to add the version string to the about screen.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You should check this question.
I am doing it this way:
try {
String pkg = mContext.getPackageName();
mVersionNumber = mContext.getPackageManager().getPackageInfo(pkg, 0).versionName;
} catch (NameNotFoundException e) {
mVersionNumber = "?";
}
回答2:
please try out this.
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;