完成后的And​​r​​oid 2.1+暂停呼入/呼出,简历 [英] Android 2.1+ Pause for incoming/outgoing call, resume when done

查看:187
本文介绍了完成后的And​​r​​oid 2.1+暂停呼入/呼出,简历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在Android中一个可靠的方法来检测呼入和呼出的开始和结束,为了做的事情一样暂停和播放音频。

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.

我也做了以下内容:

    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当对方拿起...电话通话结束时没有。我想我必须做一些愚蠢的,或缺少别的东西,我可以检查?

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?

推荐答案

您是正确的,你没有得到任何状态更新时传出手机开始。

You are correct in that you don't get any state updates when a out going call is started.

您需要连接到目的广播 ACTION_NEW_OUTGOING_CALL 。这里是一个 Android开发者博客,可以帮助理解事实上,它是一个有序的广播。这里是一个博客帖子对如何安装和使用该广播一个简单的例子。

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.

这篇关于完成后的And​​r​​oid 2.1+暂停呼入/呼出,简历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆