How can I get android device Unique ID?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Is there a unique Android device ID?
我使用下面的代码来获取Android设备IMEI,以及如何更改下面的代码来获取Android设备唯一的ID。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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(你的代码中已经有了它)
1
2TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String id = (getDeviceID1(telephonyManager));设备标识
1
2String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);蓝牙地址(这对于每个设备也是唯一的)
1
2
3
4
5private BluetoothAdapter mBtAdapter;
// Get the local Bluetooth adapter
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
String deviceMacAddress = mBtAdapter.getAddress();