大神链接http://blog.youkuaiyun.com/ljz2009y/article/details/22895297
首先获得手机的各种硬件设备的唯一标识。
TelephonyManager TelephonyMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); String szImei = TelephonyMgr.getDeviceId();
String m_szAndroidID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); String m_szBTMAC = m_BluetoothAdapter.getAddress();把是个id加在一起。
String m_szLongID = szImei
+ m_szAndroidID+ m_szWLANMAC + m_szBTMAC;
通过MD5生成唯一的识别码。(是一个方法直接调用,把合成的string放进去就可以了)
public String getId(String m_szLongID){ 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 = new String(); for (int i=0;i<p_md5Data.length;i++) { int b = (0xFF & p_md5Data[i]); // 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(); return m_szUniqueID; }