简体   繁体   English

如何在通话过程中获得新来电的呼叫等待状态

[英]How to get the call waiting state of a new incoming call during a phone conversation

I am working with an android application which reads the phone states of incoming phone calls. 我正在使用一个Android应用程序,该应用程序读取传入电话的电话状态。 And i have successfully captured the ringing,off-hook and idle states. 而且我已经成功捕获了振铃,摘机和空闲状态。 But the problem is that i need to get the Call Waiting state of a new incoming call. 但是问题是我需要获取来电的“ 呼叫等待”状态。 When I tried to catch the state of the new call it always giving the same state OFFHOOK for both answering and hangup . 当我尝试捕获新呼叫的状态时,它总是为接听挂断提供相同的状态OFFHOOK Is there any way to distinguish the scenario.?? 有什么办法可以区分这种情况。

 public class CustomPhoneStateListener extends PhoneStateListener { private static final String TAG = "CallListening"; int prev_state=0; int call_num = 0; private Context context; public static String incoming_nr = null; public static Boolean dialog = false; public static Boolean new_call_ring=false; public static Boolean cut = false; public static String first_number ; public CustomPhoneStateListener(Context context){ this.context = context; } @Override public void onCallStateChanged(int state, String incomingNumber){ if(incomingNumber!=null&&incomingNumber.length()>0){ if(incoming_nr == null){ incoming_nr=incomingNumber; first_number = incomingNumber; call_num=1; } else incoming_nr = incomingNumber; } switch (state) { case TelephonyManager.CALL_STATE_RINGING: Log.d(TAG, "CALL_STATE_RINGING ==>" + incoming_nr); prev_state = state; if(!(first_number.equals(incoming_nr))){ if(!cut){ Log.d(TAG,"new call ringing "+incoming_nr); new_call_ring = true; } } break; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d(TAG, "CALL_STATE_OFFHOOK ==>" + incoming_nr); if(!(first_number.equals(incoming_nr))){ if(new_call_ring=true){ Log.d(TAG,"new call answered or hangup"); } } prev_state = state; break; case TelephonyManager.CALL_STATE_IDLE: cut = true; Log.d(TAG, "CALL_STATE_IDLE==>" + incoming_nr); // NumberDatabase database=new NumberDatabase(mContext); if ((prev_state == TelephonyManager.CALL_STATE_OFFHOOK)) { prev_state = state; //Answered Call which is ended Log.d(TAG, "The call is answered :" + incoming_nr); } 

i think i come late hear but i like to share my solution : Telephone manager does not Provide Direct 'Waiting' state in android There are main three states: 我想我来晚了,但我想分享我的解决方案:电话管理器未在android中提供直接的“等待”状态,主要有以下三种状态:

1)'IDLE' - when device in idle generally after hangup or if you not use phone 1)“空闲”-当设备在挂断后通常处于空闲状态或不使用电话时

2)'RINGING' - ringing (when incoming call coming) 2)'RINGING'-振铃(来电时)

3)'OFF_HOOK' - The phone is off the hook Now you have to play between these three states: 3)'OFF_HOOK'-电话不挂机现在您必须在这三种状态之间进行播放:

My logic id when first call coming you pick and than second call come in live line so you have to check in Ringing state(because when incoming call come its detect by RINGING state) like below: 我的逻辑ID(当您接听的第一个电话接听时)而不是第二个电话进入实时线路,因此您必须检查振铃状态(因为当来电通过RINGING状态检测到时)如下所示:

 case TelephonyManager.CALL_STATE_RINGING:
         isIncoming = true;
         incomingNumber1 = incomingNumber;
         if(lastState==TelephonyManager.CALL_STATE_OFFHOOK){
                //its in waiting state add your logic detect 2nd number hear
                Log.e("Hear","2nd call come ");
            } else {
                //not in waiting state only first call detect only line 1 in ringing
            }
         break;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM