HOW TO GET THE BUILD/VERSION NUMBER OF YOUR ANDROID APPLICATION?

Felix Pickles

Total Post:24

Points:168
Posted by  Felix Pickles
 665  View(s)
Ratings:
Rate this:
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 AndroidManifest.xml?
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: How to get the build/version number of your Android application?

    Use:
    PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    version = pInfo.versionName;

    OR
    String versionName = context.getPackageManager()
        .getPackageInfo(context.getPackageName(), 0).versionName;

    If you're using the Gradle plugin/Android Studio, as of version 0.7.0, version code and version name are available statically in BuildConfig:
    int versionCode = BuildConfig.VERSION_CODE;
    String versionName = BuildConfig.VERSION_NAME;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!