Speaking about the unique identifiers of Android, I'm sure everyone saw this , however I am also trying to find a solution that uniquely identifies any Android device. I would be happy to use a publicly released class, but I have not found it yet.
In my situation, the requirement is to be able to uniquely identify any devices that have some form of Internet connection (for example, GPRS or Wi-Fi), and run at API level 8 (v2.2 Froyo). I do not know any devices that do not have Wi-Fi or a SIM card, so let me know if they are!
We solved this problem on iOS using the hash of the Wi-Fi MAC address, as all iOS devices must have this. However, for Android, methods (for example, replies to the SO message mentioned above) belong to the TelephonyManager class, which can return null (for example, when the device does not have a SIM card connection, for example, with Nexus 7) or getContext().getContentResolver(), Secure.ANDROID_ID , which according to here is not 100% more reliable than the versions before Froyo (which I was lucky). However, he does not ask any problems after Froyo, so if they are, let me know! I also read that this can return null . According to here, it may change to factory reset, but this is not a serious problem.
So, I put it together to create a reliable-unique-GUID GUID: [ This method has not completed! ]
public static String GetDeviceId(Context context) { // Custom String Hash 1 StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("someRandomData"); // Not really needed, but means the stringBuilders value won't ever be null // TM Device String final TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); String tmDeviceId = tm.getDeviceId(); // Could well be set to null! LogMsg.Tmp("TM Device String [" + tmDeviceId + "]"); // Custom String Hash 2 stringBuilder.append(tmDeviceId); int customHash = stringBuilder.toString().hashCode(); LogMsg.Tmp("Custom String hash [" + customHash + "]"); // Device ID String String androidIDString = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); LogMsg.Tmp("Device ID String [" + androidIDString + "]"); // Combined hashes as GUID UUID deviceUuid = new UUID(androidIDString.hashCode(), ((long)customHash << 32)); LogMsg.Tmp("Combined hashes as GUID [" + deviceUuid.toString() + "]"); return deviceUuid.toString(); }
Thus, you can set tmDeviceId to null , in this case customHash will be the same regardless of the device, but then this in combination with androidIDString should be globally unique. I think. Obviously, I will need to work if tmDeviceId AND androidIDString not available and throw an exception there.
So ... is this overkill? If so, is it safe to just use context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID ?