4

I use the command: adb devices to list the attached devices. On my computer I get : List of devices attached HT9CTP820988 device

My question is: how can I get this id (HT9CTP820988) programmatically ?

Arutha
  • 26,088
  • 26
  • 67
  • 80
  • Did you ever figure this out? Doesn't seem like any of the answers are correct. – Jens Zalzala Sep 17 '15 at 14:20
  • Found the correct answer here: http://stackoverflow.com/questions/11029294/android-how-to-programmatically-access-the-device-serial-number-shown-in-the-av – Jens Zalzala Sep 17 '15 at 14:35

6 Answers6

1

What you're seeing with the adb devices command is the serial number:

Serial number — A string created by adb to uniquely identify an emulator/device instance by its console port number. The format of the serial number is -. Here's an example serial number: emulator-5554

(refererence: http://developer.android.com/guide/developing/tools/adb.html)

When you ask "how can I get this id programmatically" what exactly do you mean? From an Android app or from a desktop app?

0

How about this one?

http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID

edit: Hmm I recall this, it can't be right; the ANDROID_ID is supposed to be 64-bit. Maybe the string you see is given by the USB driver?

volley
  • 6,651
  • 1
  • 27
  • 28
0

Look at Settings.ACTION_DEVICE_INFO_SETTINGS and answers that have already been given in the past How to find serial number of Android device?

Community
  • 1
  • 1
rds
  • 26,253
  • 19
  • 107
  • 134
  • String deviceId = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID); -> doesn't returns the same ID than adb devices !! – Arutha Dec 16 '10 at 09:00
0

I think the emulator id's purpose is to identify the emulator and devices in the development environment. And it may not be accessible from the phone.

Mudassir
  • 13,031
  • 8
  • 59
  • 87
0

I'm Using the following code...

String aid = Settings.Secure.getString(getContext().getContentResolver(), "android_id");

    Object obj = null;
    try {
        ((MessageDigest) (obj = MessageDigest.getInstance("MD5"))).update(                                   aid.getBytes(), 0, aid.length());

        obj = String.format("%032X", new Object[] { new BigInteger(1,                                   ((MessageDigest) obj).digest()) });
    } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
        obj = aid.substring(0, 32);
    }
AtifSayings
  • 756
  • 14
  • 23
0

It's possible by changing *strings_dev* struct from drivers/usb/gadget/android.c

Tiago Maluta
  • 153
  • 1
  • 1
  • 9