[英]Get Android device ID shown in adb
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? 如何将Android设备ID字符串(使用Java代码Android 2.2+)连接到计算机( 例如,在eclipse“ Serial number”字段中显示 ),或者将“ adb devices”输入到cmd,该字符串如何显示? I know it's not ANDROID_ID or telephonyManager.getdeviceId() or Build.SERIAL but I can't find what is it...
我知道它不是ANDROID_ID或telephonyManager.getdeviceId()或Build.SERIAL,但是我找不到它是什么...
the only universal way is to pull the number from USB interface settings: 唯一通用的方法是从USB接口设置中提取号码:
/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. 其中一些选择不填充
ro.serialno
属性。
If you need the id shown by the adb devices
command, then it is indeed Build.SERIAL
. 如果您需要
adb devices
命令显示的ID,则它实际上是Build.SERIAL
。
The value shown in Eclipse seems to be just a concatenation of Build.MANUFACTURER
, Build.MODEL
and Build.SERIAL
. Eclipse中显示的值似乎只是
Build.MANUFACTURER
, Build.MODEL
和Build.SERIAL
。
At least these are the results when testing on Nexus devices. 在Nexus设备上进行测试时,至少这些是结果。
尝试使用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 将
android:name="android.permission.READ_PHONE_STATE"
到清单
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String id = telephonyManager.getDeviceId();
If u want to get android_id , u can use 如果您想获取android_id,则可以使用
private String getAndroidID() {
String androidId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
return androidId;
}
In case u want device id , u can use 如果您想要设备ID,则可以使用
private TelephonyManager getTelephonyManager() {
TelephonyManager telephonyManager = ( TelephonyManager )getSystemService( Context.TELEPHONY_SERVICE );
return telephonyManager;
}
private String getIMEIStringOfDevice() {
String imeiString = getTelephonyManager().getDeviceId();
return imeiString;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.