How to get phone number of an android CDMA phone?

青春壹個敷衍的年華 提交于 2019-12-01 07:30:50

问题


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


回答1:


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" />



回答2:


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



来源:https://stackoverflow.com/questions/3696489/how-to-get-phone-number-of-an-android-cdma-phone

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