【问题标题】:How to get the call waiting state of a new incoming call during a phone conversation如何在通话过程中获取新来电的呼叫等待状态
【发布时间】:2016-01-13 17:09:08
【问题描述】:

我正在使用一个 android 应用程序来读取来电的电话状态。我已经成功地捕捉到了振铃、摘机和空闲状态。但问题是我需要获得 来电的 Call Waiting 状态。 当我试图捕捉新呼叫的状态时,它总是为 answeringhangup 提供相同的状态 OFFHOOK。 有什么方法可以区分场景吗??

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);
                        }

【问题讨论】:

    标签: android phone-call telephonymanager phone-state-listener busy-waiting


    【解决方案1】:

    我想我来晚了,但我喜欢分享我的解决方案: 电话管理器在 android 中不提供直接“等待”状态 主要有以下三种状态:

    1)'IDLE' - 当设备在挂机后通常处于空闲状态或您不使用手机时

    2)'RINGING' - 响铃(来电时)

    3)'OFF_HOOK' - 电话已摘机 现在你必须在这三种状态之间进行游戏:

    我的逻辑 id 当你第一次来电时选择,而不是第二次来电进入实时线路,所以你必须检查振铃状态(因为当来电时它被振铃状态检测到),如下所示:

     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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多