How to get the build/version number of your Android application?

前端 未结 30 1769
刺人心
刺人心 2020-11-22 11:00

I need to figure out how to get or make a build number for my Android application. I need the build number to display in the UI.

Do I have to do something with

30条回答
  •  感情败类
    2020-11-22 11:18

    private String GetAppVersion(){
            try {
                PackageInfo _info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
                return _info.versionName;
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                return "";
            }
        }
    
        private int GetVersionCode(){
            try {
                PackageInfo _info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
                return _info.versionCode;
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                return -1;
            }
        }
    

提交回复
热议问题