How to get the device serial number?

2

I am using the following code to get the device serial number:

String serial = Build.class.getField("SERIAL").get(null);

But the result is not the same when I check the serial number on the device.

    
asked by anonymous 08.03.2018 / 14:40

1 answer

4

According to the documentation you should use

Build.getSerial();

which returns the hardware serial number, if available.

Requires API level 26 and requires READ_PHONE_STATE permission.

In previous versions use Build.SERIAL .

If the reason for getting Serial is to want to identify the device where the application is running consider what is said at Best practices for unique identifiers . It may also be useful: Changes to Device Identifiers in Android O .

    
08.03.2018 / 14:50