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.
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.
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 .