Getting Android Device Identifier From ADB and Android SDK

狂风中的少年 提交于 2020-03-17 04:02:33

问题


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.


回答1:


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



回答2:


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




回答3:


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




回答4:


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()




回答5:


Simple as that with adb

adb devices -l



回答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]



回答7:


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

adb -s <YOUR-DEVICE-ID> shell getprop



回答8:


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

example:

[net.hostname]: [android-a487e0560d669e4a]



回答9:


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\'"



回答10:


you should probably use IMEI:

    TelephonyManager m = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String imei = m != null ? m.getDeviceId() : null;


来源:https://stackoverflow.com/questions/5486694/getting-android-device-identifier-from-adb-and-android-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!