/** * Return pseudo unique ID * @return ID */public static String getUniquePsuedoID() { // Ifallelse fails, if the user does have lower than API 9 (lower // than Gingerbread), has reset their device or'Secure.ANDROID_ID' // returns'null', then simply the ID returned will be solely based // off their Android device information. This iswhere the collisions // can happen. // Thanks http://www.pocketmagic.net/?p=1662! // Try notto use DISPLAY, HOST or ID - these items could change. // If there are collisions, there will be overlapping data String m_szDevIDShort = "35" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10) + (Build.CPU_ABI.length() % 10) + (Build.DEVICE.length() % 10) + (Build.MANUFACTURER.length() % 10) + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10);
// Thanks to @Roman SL! // http://stackoverflow.com/a/4789483/950427 // Only devices with API >= 9 have android.os.Build.SERIAL // http://developer.android.com/reference/android/os/Build.html#SERIAL // If a user upgrades software or roots their device, there will be a duplicate entry String serial = null; try { serial = android.os.Build.class.getField("SERIAL").get(null).toString();
// Go ahead andreturn the serialfor api => 9 returnnewUUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); } catch (Exceptionexception) { // String needs to be initialized serial = "serial"; // somevalue }
// Thanks @Joe! // http://stackoverflow.com/a/2853253/950427 // Finally, combine the values we have foundbyusing the UUIDclasstocreate a unique identifier returnnewUUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();}