Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to get an Android device's serial number, visible to the user in "Settings > About phone/tablet/device > Status > Serial number".

Devices tested

This code snippet has been successfully tested on the following devices and Android versions :

  • Archos 133 Oxygen : 6.0.1
  • Google Nexus 5 : 6.0.1
  • Hannspree HANNSPAD 13.3" TITAN 2 (HSG1351) : 5.1.1
  • Honor 5C (NEM-L51) : 7.0
  • Honor 5X (KIW-L21) : 6.0.1
  • Honor 9 Lite (LLD-L31) : 8.0
  • Huawei M2 (M2-801w) : 5.1.1
  • Samsung Galaxy S5 (SM-G900F) : 6.0.1
  • Samsung Galaxy S6 (SM-G920F) : 7.0
  • Samsung Galaxy Tab 4 (SM-T530) : 5.0.2
  • Xiaomi Mi 8 (M1803E1A) : 8.1.0
import android.os.Build;
import java.lang.reflect.Method;
public class Device {
/**
* @return The device's serial number, visible to the user in {@code Settings > About phone/tablet/device > Status
* > Serial number}, or {@code null} if the serial number couldn't be found
*/
public static String getSerialNumber() {
String serialNumber;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
// (?) Lenovo Tab (https://stackoverflow.com/a/34819027/1276306)
serialNumber = (String) get.invoke(c, "gsm.sn1");
if (serialNumber.equals(""))
// Samsung Galaxy S5 (SM-G900F) : 6.0.1
// Samsung Galaxy S6 (SM-G920F) : 7.0
// Samsung Galaxy Tab 4 (SM-T530) : 5.0.2
// (?) Samsung Galaxy Tab 2 (https://gist.github.com/jgold6/f46b1c049a1ee94fdb52)
serialNumber = (String) get.invoke(c, "ril.serialnumber");
if (serialNumber.equals(""))
// Archos 133 Oxygen : 6.0.1
// Google Nexus 5 : 6.0.1
// Hannspree HANNSPAD 13.3" TITAN 2 (HSG1351) : 5.1.1
// Honor 5C (NEM-L51) : 7.0
// Honor 5X (KIW-L21) : 6.0.1
// Huawei M2 (M2-801w) : 5.1.1
// (?) HTC Nexus One : 2.3.4 (https://gist.github.com/tetsu-koba/992373)
serialNumber = (String) get.invoke(c, "ro.serialno");
if (serialNumber.equals(""))
// (?) Samsung Galaxy Tab 3 (https://stackoverflow.com/a/27274950/1276306)
serialNumber = (String) get.invoke(c, "sys.serialnumber");
if (serialNumber.equals(""))
// Archos 133 Oxygen : 6.0.1
// Hannspree HANNSPAD 13.3" TITAN 2 (HSG1351) : 5.1.1
// Honor 9 Lite (LLD-L31) : 8.0
// Xiaomi Mi 8 (M1803E1A) : 8.1.0
serialNumber = Build.SERIAL;
// If none of the methods above worked
if (serialNumber.equals(""))
serialNumber = null;
} catch (Exception e) {
e.printStackTrace();
serialNumber = null;
}
return serialNumber;
}
}
@semoLi

This comment has been minimized.

Copy link

commented Sep 15, 2018

i'm tested on Samsung Galaxy A5 (SM-A500FQ) and Turkcell T-Tablet (Based ZTE).
works perfectly

@atatlisu

This comment has been minimized.

Copy link

commented Dec 20, 2018

Also works on Samsung Galaxy Tab A SM-P550.

@basmasrour

This comment has been minimized.

Copy link

commented Jan 21, 2019

what about this:
https://developer.android.com/reference/android/os/Build#SERIAL

"This field was deprecated in API level 26.
Use getSerial() instead.
this field is set to UNKNOWN"

@gmavenis

This comment has been minimized.

Copy link

commented Apr 24, 2019

Thanks for your code!
But anyone knows the key for LG devices?
I get properties by: adb shell getprop
but it doesn't return S/N inside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.