无法从 PhoneStateListener::onCallStateChanged 获取非空字符串
来源:
listener = new PhoneStateListener()
{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
Toast toast = Toast.makeText(getApplicationContext(), incomingNumber, Toast.LENGTH_LONG);
toast.show();
}
};
((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(listener , PhoneStateListener.LISTEN_CALL_STATE )
嗨,
我正在使用此代码,并具有 android.permission.READ_PHONE_STATE
权限,来获取包含已开始通话次数的 Toast 消息。我的问题是传入号码为空,无论呼叫是拨出还是拨入,都出现 toast,但为空。
我已经看到了一些解决方案,但解决方案是用完全不同的方式获取号码,我想知道我的代码是否可以满足我的需求。
感谢您的建议,
亚当
Source:
listener = new PhoneStateListener()
{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
Toast toast = Toast.makeText(getApplicationContext(), incomingNumber, Toast.LENGTH_LONG);
toast.show();
}
};
((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(listener , PhoneStateListener.LISTEN_CALL_STATE )
Hi,
I am using this code, with android.permission.READ_PHONE_STATE
permission, to get toast message including number of started call. My problem is that incomingNumber is empty, it doest not matter if call is outgoing or incomming, toast appear, but empty.
I have seen some solutions for this, but solution was to get the number with completely different way and I wanna know if my code can be used for my needs.
Thanks for advices,
Adam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请在您的申请中包含许可。
CALL_STATE_OFFHOOK
如果第一次调用则返回 null。因此您应该使用CALL_STATE_RINGING
。希望它能帮助你。
please include permission in your application.
CALL_STATE_OFFHOOK
return null if its first call. So you should useCALL_STATE_RINGING
.Hopefully it will help you.