5

The only command that I know that works on other versions is "adb shell dumpsys iphonesubinfo" but it doesn't seem to work on Android 5.0.

WebDevKris
  • 93
  • 1
  • 1
  • 7

1 Answers1

19

To get TelephonyManager.getDeviceId() you can do:

adb shell service call iphonesubinfo 1

If you have problems with parsing service call output check out https://gist.github.com/ktnr74/60ac7bcc2cd17b43f2cb

Or you can do it on the device side with this Windows one-liner:

adb shell "service call iphonesubinfo 1 | grep -o '[0-9a-f]\{8\} ' | tail -n+3 | while read a; do echo -n \\u${a:4:4}\\u${a:0:4}; done"

Or in Linux:

adb shell 'service call iphonesubinfo 1 | grep -o "[0-9a-f]\{8\} " | tail -n+3 | while read a; do echo -n "\u${a:4:4}\u${a:0:4}"; done'
Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • I should have specified on a non-routed device. Thank you for the response @Alex P. – WebDevKris Apr 01 '15 at 18:12
  • I just checked and it turns out that this specific service call does not actually require elevated privileges. – Alex P. Apr 02 '15 at 21:03
  • It is dusturbing why would some a-hole -1 you for perfectly valid answer – galets Jul 22 '15 at 20:32
  • Here is a workaround for all Android versions: http://stackoverflow.com/a/37940140/1140682 – saschoar Jun 21 '16 at 09:15
  • Starting from which Android version does it work? Also, you forgot to mention what the bottom commands return you. Is it IMEI ? Is it the same as what we should get from this: https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId() ? Currently it seems the answer is "yes" for both, at least on Android Q. But then I wonder, why have others: https://developer.android.com/reference/android/telephony/TelephonyManager.html#getImei() https://developer.android.com/reference/android/telephony/TelephonyManager.html#getDeviceId() ? – android developer Jun 29 '19 at 16:00