Android 如何在双sim卡上使用PhoneStateListener进行监听?

Android 如何在双sim卡上使用PhoneStateListener进行监听?,android,phone-state-listener,dual-sim,Android,Phone State Listener,Dual Sim,我是android开发新手。试着做一个简单的电话录音机 下面的PhoneStateListner非常适用于sim2呼入和呼出呼叫。但是当SIM1中发生传入/传出呼叫事件时,调用状态call\u state\u IDLE就在call\u state\u OFFHOOK之后被调用 AtomicBoolean isRecording = new AtomicBoolean(); public void onCallStateChanged(int state, String incomingNum

我是android开发新手。试着做一个简单的电话录音机

下面的
PhoneStateListner
非常适用于sim2呼入和呼出呼叫。但是当SIM1中发生传入/传出呼叫事件时,调用状态
call\u state\u IDLE
就在
call\u state\u OFFHOOK
之后被调用

AtomicBoolean isRecording = new AtomicBoolean(); 

public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);

        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE: // Idle... no call
                if (isRecording.get()) {
                    RecordCallService.stopRecording(context);
                    phoneCall = null;
                    isRecording.set(false);
                }
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK: // Call answered
                if(!isRecording.get())
                    RecordCallService.startRecording(context, phoneCall);
                }
                break;
            case TelephonyManager.CALL_STATE_RINGING: 
                if (null == phoneCall)
                    phoneCall = new CallLog();
                }
                break;
        }

    }