How can I get Android device ID to string (with Java code Android 2.2+) that is shown when I connect it to computer (example from eclipse "Serial number" field) or enter "adb devices" to cmd? I know it's not ANDROID_ID or telephonyManager.getdeviceId() or Build.SERIAL but I can't find what is it...
Asked
Active
Viewed 9,892 times
2
-
You want it in android app? – Green goblin Jun 03 '14 at 18:22
-
1You can try doing a getprop on "ro.serialno" system property – vishalm Jun 03 '14 at 19:21
-
@vishalm - ro.serialno empty, ril.serialnumber returns 000000000000. Also, Alex.P said this is not universal way. – mgulan Jun 03 '14 at 20:05
5 Answers
4
the only universal way is to pull the number from USB interface settings:
/sys/class/android_usb/android0/iSerial
Other than that it is up to every vendor to choose the way to store the serial number. Some of them choose not to populate ro.serialno
property.

Alex P.
- 30,437
- 17
- 118
- 169
-
can't find android_usb in /sys/class/... Also, I found this number in /cat/proc/cpuinfo – mgulan Jun 03 '14 at 19:59
-
specific location depends on android version. which one are you using? as for the `/proc/cpuinfo` - this number contains the chipset ID. some vendors may choose to use it (or part or some hash function of it) for the USB serial as well. – Alex P. Jun 03 '14 at 20:07
-
Android 2.3.3 Also, can you tell me if chipset ID (serial=) from /proc/cpuinfo can be found on every Android device? – mgulan Jun 03 '14 at 20:12
-
`/proc/cpuinfo` will contain the chip ID for all chipsets supporting it. But it does not help you with finding out the number which `adb devices` shows as very few phone manufacturers use chip ID for USB serial. Unfortunately I do not have any devices that old to check the exact location for that version. – Alex P. Jun 03 '14 at 20:38
2
If you need the id shown by the adb devices
command, then it is indeed Build.SERIAL
.
The value shown in Eclipse seems to be just a concatenation of Build.MANUFACTURER
, Build.MODEL
and Build.SERIAL
.
At least these are the results when testing on Nexus devices.

matiash
- 54,791
- 16
- 125
- 154
0
Try using the SERIAL string from android.os.build class http://developer.android.com/reference/android/os/Build.html#SERIAL

vishalm
- 477
- 5
- 12
-2
add android:name="android.permission.READ_PHONE_STATE"
to your manifest
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String id = telephonyManager.getDeviceId();

M4tchB0X3r
- 1,531
- 1
- 15
- 28
-3
If u want to get android_id , u can use
private String getAndroidID() {
String androidId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
return androidId;
}
In case u want device id , u can use
private TelephonyManager getTelephonyManager() {
TelephonyManager telephonyManager = ( TelephonyManager )getSystemService( Context.TELEPHONY_SERVICE );
return telephonyManager;
}
private String getIMEIStringOfDevice() {
String imeiString = getTelephonyManager().getDeviceId();
return imeiString;
}

Nielarshi
- 1,126
- 7
- 11
-
No, I want number that adb returns. I already wrote that non of these return number that is in example. – mgulan Jun 03 '14 at 18:38
-