如何在双卡上听PhoneStateListener?

时间:2018-05-17 07:32:03

标签: android phone-state-listener dual-sim

我是Android开发的新手。试图制作一个简单的通话记录器。

以下PhoneStateListner适用于sim2传入和传出呼叫。但是当在SIM1中发生传入/传出呼叫事件时,CALL_STATE_IDLE之后正在调用状态CALL_STATE_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;
        }

    }

0 个答案:

没有答案