We have a game published on Google Play Store that was developed in Unity 5.1.x.
We used the SystemInfo.deviceUniqueIdentifier for storing device specific data. Now, we are testing an update compiled in Unity 5.4.x, and for some odd reason, we are not getting the same id from Unity as the previous version.
I have tried by manually using the following:
Wifi MAC Address including string with all zeros (works for some devices that don’t have cellular connectivity)
Telephony ID
Android ID
With/without external storage permission
With/without permission Read/Write External Storage and/or Read Phone State
As far as I know, Android ID is not supposed to change with app upgrade. However, the mismatch in device unique identifier is quite troublesome as many of our players will lose their progress.
According to this thread from a year ago (Unique Identifier Details - Unity Engine - Unity Discussions), the Android ID supposedly changed from 5.3 to 5.4. However, I could not find any details on the nature of the change. Even the documentation is silent on what is returned by SystemInfo.deviceUniqueIdentifier. Any help in resolving this id mismatch issue will be highly appreciated.
I couldn’t pinpoint the exact problem. However, I think its because:
Unity 5.4.x and above no longer automatically adds READ_PHONE_STATE permission when using SystemInfo.deviceUniqueIdentifier AND
There has been probably a change in UID calculation (probably defaulting to Android ID instead of Telephony ID).
My solution may not work for every device. This is what I do now:
Manually request IMEI using a simple Android plugin I put together. This can be done via Unity but its much cleaner with a plugin.
If IMEI fails, my app tries using Mac ID,
If #2 fails, my app tries using all zeroes for Wifi Mac ID.
if #4 fails, I try using Android ID (just to be safe)
If everything fails, I ended up biting the bullet; player progress is deleted and new one based on Android ID is created. This will allow me to remove Read_Phone_State permission in the future (and avoid some panicking users).
For me works the following method. Instead SystemInfo.deviceUniqueIdentifier I use generateDeviceUniqueIdentifier(true) from the script “Simulating the ID in C#” in this topic - Unique Identifier Details - Unity Engine - Unity Discussions. Also manually add the permission READ_PHONE_STATE.
As a result, the obtained ID matches the ID from Unity version 5.1.