Android 手机的唯一名称

发布于 2024-10-22 01:45:37 字数 241 浏览 6 评论 0原文

我想通过使用以下方法获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一人独醉 2024-10-29 01:45:37

就我个人而言,我不会使用 ANDROID_ID。已知它有时为空,并且在恢复出厂设置后可能会发生变化。另一方面,设备 ID 始终为非空(至少根据我的经验),并且是唯一的。

您可以将此代码添加到您的Activity中以检索手机的唯一设备 ID:

TelephonyManager tm =
  (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

String device = tm.getDeviceId();

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:

TelephonyManager tm =
  (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

String device = tm.getDeviceId();
金橙橙 2024-10-29 01:45:37

结合上下文尝试一下,

String m_androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);

Try it with context,

String m_androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文