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