How to get device (AOSP) Build Number in Android devices programmatically?

26.1k views Asked by At

From within an Android Application, how can the hosting device's Build Number, as displayed in System Settings -> About Tablet -> Build Number be obtained programmatically for use within a Java Android application?

System Settings version number on tablet

Currently, I'm using "android.os.Build".

7

There are 7 answers

4
AudioBubble On BEST ANSWER

Check this code:

In Build.FINGERPRINT you'll get the Build Number of the device.

String mString = "";

  mString.concat("VERSION.RELEASE {" + Build.VERSION.RELEASE + "}");
  mString.concat("\nVERSION.INCREMENTAL {" + Build.VERSION.INCREMENTAL + "}");
  mString.concat("\nVERSION.SDK {" + Build.VERSION.SDK + "}");
  mString.concat("\nBOARD {" + Build.BOARD + "}");
  mString.concat("\nBRAND {" + Build.BRAND + "}");
  mString.concat("\nDEVICE {" + Build.DEVICE + "}");
  mString.concat("\nFINGERPRINT {" + Build.FINGERPRINT + "}");
  mString.concat("\nHOST {" + Build.HOST + "}");
  mString.concat("\nID {" + Build.ID + "}");

  ((TextView) findViewById(R.id.textView1)).setText(mString);

My Device Build Number :

My Device Build Number

FINGERPRINT return by the above code

enter image description here

2
Niranj Patel On

I hope it is return same value which you want..

String build_number = Build.FINGERPRINT;
System.out.println("Build Number" + build_number);
0
petey On

To get this value, use Build.DISPLAY. Here is an example from Verizon Note 2 ( SCH-I605 on android 4.4.2) : KOT49H.I605VRUFND7

Requires : API 3 or higher.

0
prerak On

To get only the Build Number value as shown on the "About Device" in settings, we can use the following static method:

/**
 * This method returns Build Number of the device from the OS Build fingerprint
 * @return osBuildNumber - human entered name of the device
 */
public static String getOSBuildNumber() {
    String osBuildNumber = Build.FINGERPRINT;  //"google/shamu/shamu:5.1.1/LMY48Y/2364368:user/release-keys”
    final String forwardSlash = "/";
    String osReleaseVersion = Build.VERSION.RELEASE + forwardSlash;
    try {
        osBuildNumber = osBuildNumber.substring(osBuildNumber.indexOf(osReleaseVersion));  //"5.1.1/LMY48Y/2364368:user/release-keys”
        osBuildNumber = osBuildNumber.replace(osReleaseVersion, "");  //"LMY48Y/2364368:user/release-keys”
        osBuildNumber = osBuildNumber.substring(0, osBuildNumber.indexOf(forwardSlash)); //"LMY48Y"
    } catch (Exception e) {
        Log.e("getOSBuildNumber", "Exception while parsing - " + e.getMessage());
    }

    return osBuildNumber;
}

This will just return the exact value of the build number. Please keep in mind that Android SDK refrains from doing this. Check the following snippet in BUILD class:

/** A string that uniquely identifies this build.  Do not attempt to parse this value. */
public static final String FINGERPRINT = deriveFingerprint();

/**
 * Some devices split the fingerprint components between multiple
 * partitions, so we might derive the fingerprint at runtime.
 */
private static String deriveFingerprint() {
    String finger = SystemProperties.get("ro.build.fingerprint");
    if (TextUtils.isEmpty(finger)) {
        finger = getString("ro.product.brand") + '/' +
                getString("ro.product.name") + '/' +
                getString("ro.product.device") + ':' +
                getString("ro.build.version.release") + '/' +
                getString("ro.build.id") + '/' +
                getString("ro.build.version.incremental") + ':' +
                getString("ro.build.type") + '/' +
                getString("ro.build.tags");
    }
    return finger;
}

The above method is just reverse engineering the data provided in the "deriveFingerprint()" method.

0
Starin On

Use Build.DISPLAY for Build Number

1
Juboraj Sarker On
Log.i("TAG", "SERIAL: " + Build.SERIAL);
Log.i("TAG","MODEL: " + Build.MODEL);
Log.i("TAG","ID: " + Build.ID);
Log.i("TAG","Manufacture: " + Build.MANUFACTURER);
Log.i("TAG","brand: " + Build.BRAND);
Log.i("TAG","type: " + Build.TYPE);
Log.i("TAG","user: " + Build.USER);
Log.i("TAG","BASE: " + Build.VERSION_CODES.BASE);
Log.i("TAG","INCREMENTAL " + Build.VERSION.INCREMENTAL);
Log.i("TAG","SDK  " + Build.VERSION.SDK);
Log.i("TAG","BOARD: " + Build.BOARD);
Log.i("TAG","BRAND " + Build.BRAND);
Log.i("TAG","HOST " + Build.HOST);
Log.i("TAG","FINGERPRINT: "+Build.FINGERPRINT);
Log.i("TAG","Version Code: " + Build.VERSION.RELEASE);

Ho it will work.

0
Nur El-din On

I used String Build_Number = Build.DISPLAY; to get Build number as it shown at Phone settings