How can I get Android device ID to string (with Java code Android 2.2+) that is shown when I connect it to computer ( example from eclipse "Serial number" field ) or enter "adb devices" to cmd? I know it's not ANDROID_ID or telephonyManager.getdeviceId() or Build.SERIAL but I can't find what is it...
the only universal way is to pull the number from USB interface settings:
/sys/class/android_usb/android0/iSerial
Other than that it is up to every vendor to choose the way to store the serial number. Some of them choose not to populate ro.serialno
property.
If you need the id shown by the adb devices
command, then it is indeed Build.SERIAL
.
The value shown in Eclipse seems to be just a concatenation of Build.MANUFACTURER
, Build.MODEL
and Build.SERIAL
.
At least these are the results when testing on Nexus devices.
尝试使用android.os.build类http://developer.android.com/reference/android/os/Build.html#SERIAL中的SERIAL字符串
add android:name="android.permission.READ_PHONE_STATE"
to your manifest
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String id = telephonyManager.getDeviceId();
If u want to get android_id , u can use
private String getAndroidID() {
String androidId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
return androidId;
}
In case u want device id , u can use
private TelephonyManager getTelephonyManager() {
TelephonyManager telephonyManager = ( TelephonyManager )getSystemService( Context.TELEPHONY_SERVICE );
return telephonyManager;
}
private String getIMEIStringOfDevice() {
String imeiString = getTelephonyManager().getDeviceId();
return imeiString;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.