Android unique UDID

孤街醉人 提交于 2020-01-06 08:08:26

问题


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();

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12754181/android-unique-udid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!