1

According to the net, the most recommended method in generating unique id is to use the Settings.Secure.ANDROID_ID. However, Settings.Secure.ANDROID_ID has a bug on Android 2.2. I am using Android 2.2 so I can't use it. On the other hand, there is also the mac address of the wiFi device and the TelephonyManager.getDeviceId(). The ID that I will be generating will be used as the session ID on the server side so it must be unique.

Will I be okay with just using the mac address of the wiFi as my unique ID and the device ID of the phone as fallback if the device has no wiFi interface? The application needs connection to the internet and so a wiFi interface or deviceId for phone will surely be present right? Or is it a bad idea?

I am also considering the use of UUID.randomUUID(). But even though there is a very small chance of generating the same id here, the probability still exist.

What ID can I use if that ID must also serve as session ID on the server? Also, please note that if the ID is already existing on the server, the ownership of the session will be given to the new user.

Arci
  • 6,647
  • 20
  • 70
  • 98

3 Answers3

2

You can simply create a random ID (UUID is fine for that) on the server. Then you can ensure it's not in use yet.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Thank you. As of now, I am more leaning in using UUID. I do not have access on the server and if I throw a similar id, the ownership of the session might be accidentally transferred to the new user. – Arci Nov 04 '11 at 08:05
1

I used ANDROID_ID, but i added random number in front of it and i get a random number...i check it if i had it in the base and if not i used that number...

Jovan
  • 1,741
  • 4
  • 19
  • 38
  • Thank you. But I do not have access on the server. So it is not possible for me to return a check if the number is already in use. – Arci Nov 04 '11 at 08:00
  • 1
    Than i sugest using a large enough number in front and in back of ID and you will not have any problem (I think). :D – Jovan Nov 04 '11 at 08:24
1

The device id is unique. What's wrong getting it ?

Quentin DOMMERC
  • 876
  • 1
  • 8
  • 24
  • Yes, the device id is unique but it is not present for all Android devices. Another thing is the required permission. If I'm the user, I wouldn't like to download an application that needs too many permissions. Also, I'm not sure if an Android device which has an access to internet always have a wiFi interface or a TelephonyManager. – Arci Nov 04 '11 at 07:58
  • Hmm, i think the device id is the IMEI, it is present on every devices. Also, you can see this : http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id/2853253#2853253 – Quentin DOMMERC Nov 04 '11 at 08:01
  • It is not present on every devices according to http://android-developers.blogspot.com/2011/03/identifying-app-installations.html. Not all android devices have telephony hardware. For example, wiFi-only devices doesn't have telephony hardware. But of course, if there is a WiFi, I can just use the mac address of the WiFi interface since I am only planning to use the device id as fallback if wiFi is not available. Does all Android devices which can access the internet either have a wiFi interface or telephony hardware? – Arci Nov 04 '11 at 08:13
  • You also can generate a random id. Actually, many mini random id wich you can add or idk. Example : first part : 54564524 second part : 78412354 third part... Final : 5456452478412354... There're littles chances this id is already taken... – Quentin DOMMERC Nov 04 '11 at 08:22
  • Thank you, Kentino. It is one of the reason why I'm considering the use of UUID. The chances are very low especially if I combine it with a different identifier. Is this approach secured? – Arci Nov 04 '11 at 08:36
  • Yes it is. You can combine UUID and a random number after that. Minimize the risks, you're good to go :P – Quentin DOMMERC Nov 04 '11 at 08:59