Android 手机的唯一名称
我想通过使用以下方法获取 Android 手机的唯一名称或 ID:
String uniqueID = android.provider.Settings.Secure.getString(getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
但它返回 null,我不知道问题是什么。
有什么帮助吗?
I want to get a unique name or id of the android phone by using the following :
String uniqueID = android.provider.Settings.Secure.getString(getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
but it is return null , i do not know what is the problem .
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我不会使用
ANDROID_ID
。已知它有时为空,并且在恢复出厂设置后可能会发生变化。另一方面,设备 ID 始终为非空(至少根据我的经验),并且是唯一的。您可以将此代码添加到您的
Activity
中以检索手机的唯一设备 ID:Personally, I wouldn't use
ANDROID_ID
. It's been known to be null sometimes and it can change after a factory reset. The device id on the other hand is always non-null (in my experience at least), and unique.You can add this code to your
Activity
to retrieve the unique device id of the phone:结合上下文尝试一下,
Try it with context,