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

前端 未结 30 1771
刺人心
刺人心 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:23

    First:

    import android.content.pm.PackageManager.NameNotFoundException;
    

    and then use this:

    PackageInfo pInfo = null;
    try {
         pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (NameNotFoundException e) {
         e.printStackTrace();
                }
    String versionName = pInfo.versionName;
    

提交回复
热议问题