41

I am looking for the easiest way to get a unique android device identifier from both the Android adb and the Android ADK itself.

For example, when i use the adb 'devices' command, the serial number of my connected device is outputted to the screen. I have yet to identify a method in the Android sdk to get me the same serial number.

I don't care what unique identifier is used, just something that can be easily retrieved from both the adb and android sdk. Rooting a device will not be an option.

user163757
  • 6,795
  • 9
  • 32
  • 47

12 Answers12

72

You would probably want to use ANDROID_ID.

This is how you can query its value via adb shell:

settings get secure android_id

Or by querying the settings content provider:

content query --uri content://settings/secure/android_id --projection value
Alex P.
  • 30,437
  • 17
  • 118
  • 169
15

Simple as that with adb

adb devices -l
Hadnazzar
  • 1,517
  • 19
  • 21
13

Android stores all the device related info in one or the other sqlite DB. These databases can be found in /data/data/ folder. To read these databases from adb you will need root permissions.

The android id is available in /data/data/com.android.providers.settings/databases/settings.db

So for adb use this command.

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select value from secure where name = 'android_id'"

**you must be running adb as root in adb

Community
  • 1
  • 1
BabbarTushar
  • 1,285
  • 2
  • 11
  • 20
7

The Android serial number can be retreived within the device with getprop :

getprop ro.serialno

From Java, you may want to execute it with Runtime.exec()

Community
  • 1
  • 1
McX
  • 1,296
  • 2
  • 12
  • 16
6

I use adb. First I list the attached device ID numbers with the following command:

adb devices

And the output will look something like this:

List of devices attached
YOGAA1BBB412    device

From the previous output, you will need the device ID number (eg: YOGAA1BBB412). To get the Device ID, I use the following adb command:

adb -s YOGAA1BBB412 shell getprop | grep product.model

And the output looks like this:

[ro.product.model]: [Lenovo YT3-X90F]
Jaime Ivan Cervantes
  • 3,579
  • 1
  • 40
  • 38
6

Try ANDROID_ID. As documentation says "[it] is randomly generated on first boot and should remain constant for the lifetime of the device".

Andrzej Duś
  • 1,338
  • 1
  • 10
  • 16
  • 1
    Do have any idea of how this can be accessed from adb? – user163757 Mar 30 '11 at 14:19
  • As far as I know most reliable way will be to create an application that copies it (ANDORID_ID) to database. Than you can access this database trough adb (use [sqlite3](http://developer.android.com/guide/developing/tools/adb.html#sqlite) command from shell). – Andrzej Duś Mar 30 '11 at 14:57
  • I haven't tested it myself but you may also find ANDORID_ID already stored in this places: - /data/data/com.android.providers.settings/databases/settings.db - table secure - /data/data/com.google.android.googleapps/databases/gls.db - table meta – Andrzej Duś Mar 30 '11 at 15:05
3

Please make sure your device is connected by running the below command.

adb devices -l

after that to get the android id of that device you can run the below command.

adb shell content query --uri content://settings/secure --where "name=\'android_id\'"
Abhishek
  • 3,304
  • 4
  • 30
  • 44
1

adb shell settings get secure android_id

This command returns ANDROID_ID but it may not be the same as ANDROID_ID received at code level. The application can use different min API level and the value obtained from adb shell may not match

It was possible to get the ANDROID_ID from [net.hostname] prop. It worked in API level 23.

Command to get the android_id for API level 23

adb shell getprop net.hostname

In android 8.0 and above this prop returns null due to android privacy policy changes. Hence, ANDROID_ID doesn't remain to be a reliable method of unique device id comparison.

Akash
  • 51
  • 3
0

Try this and find the id besides Android. The command gives basically all info about the phone.

adb -s <YOUR-DEVICE-ID> shell getprop
Grimthorr
  • 6,856
  • 5
  • 41
  • 53
0

Use getprop net.hostname which has an Android unique Id followed by keyword android-<64 bit Hexadecimal String>

example:

[net.hostname]: [android-a487e0560d669e4a]
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Navneet kumar
  • 1,696
  • 1
  • 17
  • 26
-1

To find everything about connected usb device on ubuntu use below command lsusb -v
See the link enter image description here it will give u device id like Bus 001 Device 005: ID 18d1:4ee7 Google Inc. So use first four "18d1" to add android usb rules

k.s.
  • 2,964
  • 1
  • 25
  • 27
-3

you should probably use IMEI:

    TelephonyManager m = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String imei = m != null ? m.getDeviceId() : null;
reflog
  • 7,587
  • 1
  • 42
  • 47
  • IMEI may not be a good proxy for a unique identifier since you can't guarantee that every device your app runs on will have a cell radio. Given that you can specify a for android.hardware.telephony, I wouldn't recommend assuming the presence of telephony hardware. On the other hand, if you're happy restricting your app to only those devices with telephony hardware, then this should be useable. – RivieraKid Mar 30 '11 at 13:29