电话唯一标识符差异
不久前,我正在寻找一种方法来唯一标识我的应用程序正在其上运行的设备。我发现了以下算法:
final TelephonyManager tm = (TelephonyManager) baseContext.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice = "" + tm.getDeviceId();
final String tmSerial = "" + tm.getSimSerialNumber();
final String androidId = "" + android.provider.Settings.Secure.getString(baseContext.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
return deviceUuid.toString();
任何人都可以向我解释为什么这偶尔会在同一设备上给我不同的结果,以及我可以采取什么措施来纠正它?
A while ago I was looking for a way to uniquely identify a device my application was running on. I found the following algorithm:
final TelephonyManager tm = (TelephonyManager) baseContext.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice = "" + tm.getDeviceId();
final String tmSerial = "" + tm.getSimSerialNumber();
final String androidId = "" + android.provider.Settings.Secure.getString(baseContext.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
return deviceUuid.toString();
Can anyone explain to me why this would occasionally be giving me differing results on the same device, and what I can do to correct it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我预计问题与 getSimSerialNumber() 有关,因为它获取一张特定 SIM 卡的序列号,因此如果手机所有者更改 SIM 卡(例如通过移动网络),该方法将返回不同的 ID。 SIM 卡是唯一的,但每个设备可能在不同时间使用不同的 SIM 卡。
I expect the problem relates to getSimSerialNumber() as that is getting the serial number for one specific SIM card, so if the owner of the phone changes the SIM (e.g. by moving network) the method will return a different ID. The SIM is unique, but each device may use different SIMs at different times.
Advantej 和 Ollie C 都发布了这个问题的答案。看一下以下页面:
http://android-developers .blogspot.com/2011/03/identifying-app-installations.html
Advantej and Ollie C both posted the answer to this question. Have a look at the following page:
http://android-developers.blogspot.com/2011/03/identifying-app-installations.html