0
这个问题曾多次提出过,但没有任何解决方案适用于我。我在kitkat(4.4.4)/ Nexus5上。以下是我试过的解决方案:如何读取Android设备上的来电号码
1)基于How to detect incoming calls, in an Android device?解决方案,我试图从“extras”中检索数字。但intent.getExtras.getString始终返回null
2)基于Get phone number of present incoming and outgoing call的解决方案,我试图从日志读取,但 “cur.getString(0)”,
我不使用TelephonyManager总是返回null在我的代码中的任何地方(尽管上面的链接似乎很少使用电话管理器)。我正在使用BroadcastReceiver。我的代码如下。我最终尝试了2种以上的解决方案,因为我在下面的回调中获得了空值(callingNumber)。
public class MyPhoneStateListener extends PhoneStateListener {
//blah blah
public void onCallStateChanged(int state, String callingNumber)
{
//callingNumber is always null, unfortunately
}
}
你必须以小写字符开头的变量名。 – 2015-04-02 17:12:29
当然是你的xml中的所有权限 – 2015-04-02 17:13:30
@Sergui:非常棒 - 谢谢 – 2015-04-03 22:47:18