android - 如何在双卡上使用 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;
}
}
解决方案
推荐阅读
- python - 如何检查python中dict的所有项目值是否相同。?
- arrays - Json Array 到 typescript 中的自定义类数组
- ios - Firebase 身份验证:Swift 中的电话号码身份验证
- python-3.x - 我的python代码没有错误。但我没有得到任何答案
- javascript - 当 Mozilla Firefox 通过链接启动时,如何始终获取 browser.webRequest.onBeforeRequest 事件?
- c++ - openCV cv::cuda::LookUpTable LUT 输入
- swift - 进行获取 api 调用
- image - 从模糊图像中提取字符
- html - Bootstrap CSS 固定 bg 定位
- rust - 如何使用 tokio-tungstenite 的 send_all 方法发送 websocket 消息流