I need to generate a unique ID for every user that uses my app. I have used the device ID but this isn't advisable (not all devices support it and it is unsafe).
What is the best way (please sample) and best library to generate a unique ID?
Thought about that but what happens if a user sells/gives way his phone? He would wipe it but if the new user would install the same app. it would generate exactly the same UUID because model etc, would not change. IMEI only works if it is a phone (CDMA or GSM). So in case of a non-phone it would skip the IMEI and the UUID would be less unique.
I rather have something like a GUID. Does anyone have a sample on the RandomSeed stuff?
Depends on the purpose of the unique ID - Since it has to be unique I assume that there will be some connectivity with a server. Could you not, therefore, let them just choose a username which could be validated against a security table, or just use their email address which would automatically be unique?
Dim r As Reflector
r.Target = r.RunStaticMethod("java.util.UUID", "randomUUID", Null, Null)
Return r.RunMethod("toString")
If a device moves along to a new user I don't want to have them the same UUID. I have authenticated and non authenticated users, the non authenticated also need to be able to store preferences on the server so they can use a GUID to do that. The authenticated users have their own unique ID tied to strong usernames and password and encrypted.
Yes, re-install is an issue indeed but both options are a problem. Having an ID linked to the device could be problematic if someone gives away or sells his phone and the new user installs the same app.
To add IMEI or mobile number would be another option but don't want to use the phone permission.
What Erel describes should work fine for most apps. but not in above situation because that method is linked to the device.
There are some other options to investigate and I can explain my users that not creating a user account can result in preferences loss after re-install because it is a temp number.