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);
1
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>
2
  • 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:/ $ 
1
  • 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. May 5 '19 at 9:52
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).

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

1
  • 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 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.