Finding app version number in code

后端 未结 2 1343
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 12:31

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.

相关标签:
2条回答
  • 2020-12-25 13:12

    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 = "?";
            }
    
    0 讨论(0)
  • 2020-12-25 13:23

    please try out this.

    PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    version = pInfo.versionName;
    
    0 讨论(0)
提交回复
热议问题