On an Android device is there a way to programmatically get the USB serial number as shown in ADB?

StackOverflow https://stackoverflow.com/questions/9045803

  •  03-12-2019
  •  | 
  •  

Question

On an Android device is there a way to programmatically get the USB serial number as shown in ADB?

Secure.getString(mApp.getContentResolver(), Secure.ANDROID_ID) is different then what is shown in ADB.

EDIT: Note the date of this question. It was asked before there was android.os.Build.SERIAL;

Was it helpful?

Solution

The easiest way to obtain serial number is :

String deviceSerialNumberFromADB = android.os.Build.SERIAL;

This serial number equals to: "adb get-serialno" or "adb devices" from command prompt (if only 1 device connected).

OTHER TIPS

Another option is:

adb shell cat /sys/class/android_usb/android0/iSerial

You have a few options here. If you wanted to get the serial number via the command line, you could run:

adb get-serialno

If you wanted to somehow get this information within your app, have a look through AdbDevice.java.

Using a UsbDeviceConnection object, you can:

// UsbDeviceConnection connection
serialNo = connection.getSerial();
Log.d(TAG, "Serial number is: " +serialNo);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top