如何获取android设备的唯一ID?
可能重复:如何获取android设备的唯一ID?,android,Android,可能重复: 我使用下面的代码来获取android设备IMEI,如何更改下面的代码来获取android设备的唯一ID String getDeviceID1(TelephonyManager phonyManager){ String id = phonyManager.getDeviceId(); if (id == null){ id = "not available"; } int phoneType = phonyManager.getPh
我使用下面的代码来获取android设备IMEI,如何更改下面的代码来获取android设备的唯一ID
String getDeviceID1(TelephonyManager phonyManager){
String id = phonyManager.getDeviceId();
if (id == null){
id = "not available";
}
int phoneType = phonyManager.getPhoneType();
switch(phoneType){
case TelephonyManager.PHONE_TYPE_NONE:
return "" + id;
case TelephonyManager.PHONE_TYPE_GSM:
return "" + id;
case TelephonyManager.PHONE_TYPE_CDMA:
return "" + id;
/*
* for API Level 11 or above
* case TelephonyManager.PHONE_TYPE_SIP:
* return "SIP";
*/
default:
return "" + id;
}
//I used to show IMEI
TextView textDeviceID = (TextView)findViewById(R.id.deviceid);
//retrieve a reference to an instance of TelephonyManager
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
textDeviceID.setText(getDeviceID1(telephonyManager));
}
在Android中,您可以获得三个不同的唯一ID
- IMEI(代码中已经有了)
- 蓝牙地址(每个设备的地址也是唯一的)
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String id = (getDeviceID1(telephonyManager));
String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
private BluetoothAdapter mBtAdapter;
// Get the local Bluetooth adapter
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
String deviceMacAddress = mBtAdapter.getAddress();