Jesse
Jesse

Reputation: 2684

Android unique UDID

Can someone tell me if the code I have been using is the proper way to get the unique id? I am suspecting i may have dupes out there and this could be causing issues on an administrative level in my company...

final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String UDID = tm.getDeviceId();

Upvotes: 0

Views: 1832

Answers (2)

Dave
Dave

Reputation: 3218

If you want a unique identifier for android there is tons of issues that you will see comes up with a simple google search. Similar to what CommonsWare mentioned.

However you can still get a unique identifier. The real question is what you want to identify. Either the user, or the device?

If you want to identify the particular user:

You want to IMSI value.

final TelephonyManager tm = (TelephonyManager)context`.getSystemService(Context.TELEPHONY_SERVICE);

String UDID = tm.getSubscriberId()

If you want to identify the hardware then you want the IMEI value:

final TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

String UDID = tm.getDeviceId()

Now: I would recommend going with the getDeviceID() option as it has less privacy implications.

But you can take it a step event further and hash this value before storing it.

However, if you can't get a proper value returned, you could always do something like get the user to enter their phone number, and verify it through an sms. Then use that as an identifier.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007534

It is the proper way to call getDeviceId(). That may not be a unique identifier, since not all devices are phones and some phones have bugs. See this Android Developers Blog post for more details.

Upvotes: 4

Related Questions