11

I know that you can find IMEI and MAC address and others by going to Settings -> About phone -> Status. You can also find IMEI by typing *#06# on the keypad. Is there any way to get the ANDROID_ID on the phone itself, as opposed to via this bit of code?

Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
Liam W
  • 8,436
  • 11
  • 40
  • 67
Kalinka
  • 121
  • 1
  • 1
  • 4

4 Answers4

8

You can do this via adb. Does not require root, as far as I know (tested on a Galaxy Nexus running 4.2.1 built from AOSP source):

shell@android:/ $ content query --uri content://settings/secure --projection value --where "name='android_id'"              
  Row: 0 value=<your ID in hexadecimal>
evandrix
  • 105
  • 4
eldarerathis
  • 36,787
  • 16
  • 144
  • 175
  • 2
    If running via a terminal emulator app, root is required. – Liam W Dec 18 '12 at 15:34
  • adb has more privileges than the local shell user. With Android 4.x (ICS and up), you can even do a full backup via ADB on an unrooted device -- which the shell user for sure cannot. – Izzy Dec 18 '12 at 17:47
7

settings get secure android_id from adb shell is the simplest, I find — no extraneous output and does not require root. (From a regular terminal on the device, root is required.)

shell@mydevice:/ $ settings get secure android_id
0123456789abcdef
shell@mydevice:/ $ 
Matthew Read
  • 50,567
  • 30
  • 145
  • 273
  • To get into adb shell: 1. Go to android_sdk/platform-tools/ with cmd or other terminal. 2. adb devices to check if your mobile can be found through USB. 3. adb shell. 4. Run command in this answer. – NumesSanguis May 05 '19 at 09:52
2

The above answer has $ content query --uri content://settings/secure --projection value --where "name='android_id'" in it

If you're executing this from shell then you'll need to escape the quotes around android_id else they get interpreted and the SQL statement doesn't have them, resulting in an unknown column.

My full command from bash looks line...
$ adb shell content query --uri content://settings/secure --projection value --where "name=\'android_id\'"

^ Not enough reputation to comment on the answer that suggested it above

  • Kind of. @eldarerathis's answer started up a shell on the device with adb shell, and then ran another command within that shell. This works fine without escaping the quotes. Your answer is running a single command on the main machine; for this you do need to escape the quotes. – Mark Sep 11 '19 at 00:51
2

As eldarerathis variant didn't work out for me, and I didn't want to install an app just for that, I've found a different way. Only possible drawback: It requires root.

adb shell
$ su
# cd /data/data/com.android.providers.settings/databases
# sqlite3 settings.db
sql> select * from secure where name='android_id';
26|android_id|1234567890abcdef1

The android_id is found in the third column here (anonymized in the example).


EDIT:

Note that this is NOT the android_id used by the Google apps. Google seems to have decided for some confusion here. For Play Services, there's a separate android_id stored by GTalk, as pointed out by a blog post (also see this answer by HassleFixes, who is the autor of StripSearch, and thankfully pointed this out in the comments):

  • call up your dialer
  • dial *#*#8255#*#*
  • watch out for "Device ID"
  • remove the leading android-
  • what remains, is the android_id used by Google Services

I've verified that: the android_id retrieved this way works fine on a device with no Google-Apps installed (used with the BlankStore provided by the NOGAPPS project).

Izzy
  • 91,166
  • 73
  • 343
  • 943