Aaron Ullal
Aaron Ullal

Reputation: 5245

How to find ANDROID_ID from device NOT programmatically

I am currently retrieving my device's ANDROID_ID programmatically with the following code:

Settings.Secure.getString(this._context.getContentResolver(), Settings.Secure.ANDROID_ID);

How can I retrieve the same ID "visually" from the device (so not programmatically)?

I have looked everywhere but I have not been able to find it in settings, and neither using apps such as DeviceId

Upvotes: 2

Views: 6853

Answers (3)

Alex Lipov
Alex Lipov

Reputation: 13958

We can split the answer into two parts, depending on which Android API level device has.


Device with API level < Android 8.0 (Oreo)

The ANDROID_ID value can be retrieved using this adb command:

# this will retrieve current user's ANDROID_ID
$ adb shell settings get secure android_id  
ba003ff1b4125132
# you can also get the value of each other user's value by specifying --user <USER_ID>
$ adb shell settings get --user 10 secure android_id  
3e6a5f43bd80ea6

On an emulator (or on a rooted device), you'll be able to find the ANDROID_ID using the following commands:

# first, switch into a root mode and open a shell
$ adb root
$ adb shell
# find which users exist on a device (this example shows two users having ID 0 and 10)
$ ls -l /data/system/users
drwx------ 4 system system 4096 2019-10-09 18:05 0
-rw------- 1 system system  267 2019-10-09 18:05 0.xml
drwx------ 5 system system 4096 2019-10-09 18:05 10
-rw------- 1 system system  385 2019-10-09 18:05 10.xml
-rw------- 1 system system  367 2019-10-09 18:05 userlist.xml 
# the ANDROID_ID located in settings_secure.xml file
$ cat 0/settings_secure.xml | grep android_id
  <setting id="31" name="android_id" value="ba003ff1b4125132" package="android" />  
# similarly, we can find user 10's value:
$ cat 10/settings_secure.xml | grep android_id
  <setting id="31" name="android_id" value="3e6a5f43bd80ea6" package="android" />  


Device with API level >= Android 8.0 (Oreo)

Same technique as above can be used on 8.0 and later devices, however the (global ANDROID_ID) value it returns can be seen only by system processes.

adb doesn't support retrieving a particular application's ANDROID_ID at this time, because its value is being written into a separate file (settings_ssaid.xml, while adb allows to access only values from system, secure or global). However, on emulator or on a rooted device this can be easily achieved:

$ adb root
$ adb shell
# here I'm using user with ID 0
$ cd /data/system/users/0
$ cat settings_ssaid.xml  
<settings version="-1">
  <setting id="0" name="userkey" value="E4FC4CFF14039F5AD44AD63F70007F85FDBBE1FF9BCB9FF5331B3FD33E057461" package="android" defaultValue="E4FC4CFF14039F5AD44AD63F70007F85FDBBE1FF9BCB9FF5331B3FD33E057461" defaultSysSet="true" tag="null" />
  <setting id="4" name="10072" value="9d5f269e42d4ca76" package="info.osom.ssaid" defaultValue="9d5f269e42d4ca76" defaultSysSet="false" tag="null" />
</settings>

In this example, I have one application with package name info.osom.ssaid, whose ANDROID_ID value is 9d5f269e42d4ca76.

Upvotes: 2

Sotiris S. Magionas
Sotiris S. Magionas

Reputation: 799

Why do you need the ANDROID_ID? If you need it for auhentication reasons, ( to know which device is which) , be advised that this value is not constant but may change overtime. You can read more about it here.

The only value that is unique and constant and can be used to identify your device is it's MacAddress but even that is discouraged.

If you need this value for some other reason, ignore this answer.

Upvotes: -1

Philippe Banwarth
Philippe Banwarth

Reputation: 17755

There is no global ANDROID_ID anymore. Since Android 8 each application sees a different value. More specifically the value depends on the signature used to sign the application, the user (on multi users devices) and the device.

See Settings.Secure.ANDROID_ID for more details

Upvotes: 2

Related Questions