Finding app version number in code

*爱你&永不变心* 提交于 2019-11-30 11:55:10

问题


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;


来源:https://stackoverflow.com/questions/2881641/finding-app-version-number-in-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!