Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hardware serial number of Android device

I need to get the hardware serial code of Android device where my app is installed. This hardware serial number is the one that you can see on Settings > About Device > Status > Serial number.

I though I would get it using Settings.Secure.ANDROID_ID or android.os.Build.SERIAL, but neither of them worked, meaning that they didn't give me unique identifier I'm looking for. For instance android.os.Build.SERIAL got me the unique ID shown on ADB when you run the command adb devices.

Notice that the goal of this question is not to find another unique identifier that could help me, it's only about getting the device hardware serial number.

Thanks for the help.

EDIT:

Please be clear that I'm not looking for the value provided by the String android.os.BUILD.SERIAL. I know how to get that value but I'm not interested in it.

I have a Samsung device, therefore, the serial number they used is different than the one provided by android.os.BUILD.SERIAL.

like image 814
Storo Avatar asked Nov 05 '14 18:11

Storo


People also ask

How can I find my serial number in Android programmatically?

Android App Development for Beginners Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken text view to show serial number.

How can I find the serial number of my phone without the phone?

Call your local carrier branch and ask for the serial number. In the event that you can't find the serial number on the phone, its packaging, or your online account, you can call your closest carrier branch and ask for the serial number.

How do I find the serial number of my Android 10?

How to get an Android device's serial number, visible to the user in "Settings > About phone/tablet/device > Status > Serial number".


Video Answer


1 Answers

The solution is very simple:

Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
serialNumber = (String) get.invoke(c, "sys.serialnumber", "Error");
if(serialNumber.equals("Error")) {
    serialNumber = (String) get.invoke(c, "ril.serialnumber", "Error");
}

This will get you the serial number of most samsung devices. I use the "sys.serialnumber" value to get the serial number of my SM-T210 (Galaxy Tab 3) and SM-T230 (Galaxy Tab 4) tablets, but probably works with a lot more Samsung tablets. The "ril.serialnumber" is to get the value on my Samsung GT-I8550L (Galaxy Win).

I hope this helps.

like image 53
Storo Avatar answered Sep 18 '22 09:09

Storo