如何获取 Android CDMA 手机的电话号码?

发布于 2024-09-19 11:56:01 字数 106 浏览 1 评论 0原文

TelephonyManager.getLine1Number() 适用于 GSM 手机,但不适用于 CDMA 手机。是否有可能通过 Android API 调用获取 CDMA 手机的电话号码?谢谢

The TelephonyManager.getLine1Number() works on GSM phones, but not CDMA phones. Is it possible to get the phone number of a CDMA phone through android API calls at all? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

青衫儰鉨ミ守葔 2024-09-26 11:56:29

我已在 Motorola Droid 和 HTC EVO 4G(均为 CDMA)上成功使用了以下内容。

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = telephonyManager.getLine1Number();

确保您在清单中请求正确的权限。

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

I've successfully used the following on a Motorola Droid and HTC EVO 4G which are both CDMA.

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = telephonyManager.getLine1Number();

Make sure you are requesting the correct permission in your manifest.

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
娇柔作态 2024-09-26 11:56:22

尽管建议的方法可能有效,但某些运营商(我相信这是他们的选择)不提供此号码,而是返回 null。

文档中说明了返回 null: http://developer.android.com/reference /android/telephony/TelephonyManager.html
(向下滚动到该方法的文档)。

以下是可能的解决方法的链接:
http://code.google.com/p/android/issues /detail?id=1110#c5

Although the method suggested might work, some carriers (I believe it's their choice) do not provide this number, returning null instead.

Returning null is stated in the documentation: http://developer.android.com/reference/android/telephony/TelephonyManager.html
(scroll down to the method's documentation).

Here is a link for a possible work-around:
http://code.google.com/p/android/issues/detail?id=1110#c5

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