How to get Serial number of Android device programmatically

12,241

Solution 1

Use this upto Android 7.1(SDK 25)

Build.SERIAL

And this for Android 8(SDK 26+)

Build.getSerial()

Solution 2

You can use this gist file for get device id. It works on all device before android Pie. If you targeting pie so you can add below code on gist file.

if (serialNumber.equals("unknown")){
   try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
           serialNumber = Build.getSerial();
        }
    } catch (SecurityException e) {
        e.printStackTrace();
        Log.d("responseData", String.valueOf(e.getMessage()));
    }
}

put this code above this line of code

// If none of the methods above worked
if (serialNumber.equals("")) {
    serialNumber = null;
}

I tried this code on Nokia 6.1 plus and its working.

Share:
12,241
Arslan Tazhibaev
Author by

Arslan Tazhibaev

Updated on June 08, 2022

Comments

  • Arslan Tazhibaev
    Arslan Tazhibaev almost 2 years

    How to find the serial number of the device with Android. I need a serial number that is in About device -> Status -> Serial number

    Build.Serial returns to me a different value

    enter image description here