首页 > 解决方案 > 如何在双卡上使用 PhoneStateListener 收听?

问题描述

我是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;
        }

    }

标签: androidphone-state-listenerdual-sim

解决方案


推荐阅读