android device ID (not IMEI)
I use the command: adb devices to list the attached devices. On my compu开发者_StackOverflow社区ter I get : List of devices attached HT9CTP820988 device
My question is: how can I get this id (HT9CTP820988) programmatically ?
What you're seeing with the adb devices
command is the serial number:
Serial number — A string created by adb to uniquely identify an emulator/device instance by its console port number. The format of the serial number is -. Here's an example serial number: emulator-5554
(refererence: http://developer.android.com/guide/developing/tools/adb.html)
When you ask "how can I get this id programmatically" what exactly do you mean? From an Android app or from a desktop app?
How about this one?
http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID
edit: Hmm I recall this, it can't be right; the ANDROID_ID is supposed to be 64-bit. Maybe the string you see is given by the USB driver?
Look at Settings.ACTION_DEVICE_INFO_SETTINGS
and answers that have already been given in the past How to find serial number of Android device?
I think the emulator id's purpose is to identify the emulator and devices in the development environment. And it may not be accessible from the phone.
It's possible by changing *strings_dev* struct from drivers/usb/gadget/android.c
I'm Using the following code...
String aid = Settings.Secure.getString(getContext().getContentResolver(), "android_id");
Object obj = null;
try {
((MessageDigest) (obj = MessageDigest.getInstance("MD5"))).update( aid.getBytes(), 0, aid.length());
obj = String.format("%032X", new Object[] { new BigInteger(1, ((MessageDigest) obj).digest()) });
} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
obj = aid.substring(0, 32);
}
精彩评论