5. The BT MAC Address string, 只在有蓝牙的设备上运行。并且要加入android.permission.BLUETOOTH 权限.
BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter
m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String m_szBTMAC = m_BluetoothAdapter.getAddress();
Returns: 43:25:78:50:93:38 . 蓝牙没有必要打开,也能读取。
Combined Device ID
综上所述,我们一共有五种方式取得设备的唯一标识。它们中的一些可能会返回null,或者由于硬件缺失、权限问题等获取失败。
但你总能获得至少一个能用。所以,最好的方法就是通过拼接,或者拼接后的计算出的MD5值来产生一个结果。
String m_szLongID = m_szImei + m_szDevIDShort
+ m_szAndroidID+ m_szWLANMAC + m_szBTMAC;
// compute md5
MessageDigest m =null;
try{
m =MessageDigest.getInstance("MD5");
}catch(NoSuchAlgorithmException e){
e.printStackTrace();
}
m.update(m_szLongID.getBytes(),0,m_szLongID.length());
// get md5 bytes
byte p_md5Data[]= m.digest();
// create a hex string
String m_szUniqueID =newString();
for(int i=0;i<p_md5Data.length;i++){
int b =(0xFF& p_md5Data);
// if it is a single digit, make sure it have 0 in front (proper padding)
if(b <=0xF)
m_szUniqueID+="0";
// add number to string
m_szUniqueID+=Integer.toHexString(b);
}// hex string to uppercase
m_szUniqueID = m_szUniqueID.toUpperCase();
通过以上算法,可产生32位的16进制数据:
9DDDF85AFF0A87974CE4541BD94D5F55
现在你就可以对其进行你的应用了。