安卓 2.1+暂停接听/拨出电话,完成后恢复
Android 中是否有可靠的方法来检测传入和传出呼叫的开始和结束,以便执行暂停和播放音频等操作。
我已完成以下操作:
telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
callEventListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_IDLE){
//....
}
else if (state == TelephonyManager.CALL_STATE_RINGING){
//....
}
}
};
telephonyManager.listen(callEventListener, PhoneStateListener.LISTEN_CALL_STATE);
这似乎适用于传入呼叫,但对于传出呼叫,当其他人接听电话时,我会收到 CALL_STATE_IDLE...而不是在电话结束时。我想我一定是做了一些愚蠢的事情,或者错过了其他我可以检查的事情?
Is there a reliable way in Android to detect the beginning and end of incoming and outgoing calls, in order to do things like pause and play audio.
I have done the following:
telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
callEventListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_IDLE){
//....
}
else if (state == TelephonyManager.CALL_STATE_RINGING){
//....
}
}
};
telephonyManager.listen(callEventListener, PhoneStateListener.LISTEN_CALL_STATE);
Which seems to work for incoming calls, but for outgoing calls I get the CALL_STATE_IDLE when the other person picks up...not when the phone call ends. I figure I must be doing something stupid, or missing something else that I can check?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是正确的,因为当开始拨出呼叫时您没有收到任何状态更新。
您需要挂钩意图广播 ACTION_NEW_OUTGOING_CALL。这是一个 Android 开发者博客,可能有助于了解事实上,这是一个有序的广播。这里有一篇博客文章,其中包含如何设置和使用此广播的简单示例。
You are correct in that you don't get any state updates when a out going call is started.
You need to hook into the intent broadcast ACTION_NEW_OUTGOING_CALL. Here is a Android Developer Blog that may help understand the fact that it's a ordered broadcast. And here is a blog post with a simple example of how to setup and use this broadcast.