Finding app version number in code

后端 未结 2 1345
伪装坚强ぢ
伪装坚强ぢ 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 = "?";
            }
    

提交回复
热议问题