当我们有来电,拨出和断开呼叫时,我正在使用PhoneStateListener
来收听呼叫状态。一切正常。但我的问题是我希望CALL_STATE_IDLE
,CALL_STATE_OFFHOOK
中的电话号码断开连接。
当我们有来电时,我可以收到来电号码。但是当电话结束时,我无法获得断开连接的电话号码。我正在使用下面的代码。
任何人都可以告诉我如何获取电话号码CALL_STATE_IDLE
,CALL_STATE_OFFHOOK
。
// Call State Listener
private final class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String inComingNumber) {
switch (mCallState) {
case TelephonyManager.CALL_STATE_IDLE:
if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
// New Outgoing Call
} else if (state == TelephonyManager.CALL_STATE_RINGING) {
System.out.println("New Incoming Call");
System.out.println("CallStateListener Incoming Number: " + inComingNumber);
// New Incoming Call
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if (state == TelephonyManager.CALL_STATE_IDLE) {
// Call Disconnected
System.out.println("CallStateListener Disconnected Number: " + inComingNumber);
System.out.println("Call Disconnected");
} else if (state == TelephonyManager.CALL_STATE_RINGING) {
// Another Call Waiting
}
break;
case TelephonyManager.CALL_STATE_RINGING:
if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
System.out.println("Call Received");
System.out.println("CallStateListener Received Number: " + inComingNumber);
// Call Received
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
System.out.println("CallStateListener Missed Number: " + inComingNumber);
// Call Missed
}else if(state == TelephonyManager.CALL_STATE_RINGING) {
}
break;
}
mCallState = state;
}
}
当我使用上面的PhoneStateListener时,我得到的日志为
CallStateListener Incoming Number: 4121312323
CallStateListener Missed Number:
CallStateListener Received Number:
CallStateListener Disconnected Number:
我只能在RINGINE状态下获得来电号码,但我无法获得呼叫接收状态电话号码,呼叫未接来电状态号码和已断开连接的电话号码。请任何帮助指导我。感谢
答案 0 :(得分:0)
尝试打开这样的活动:
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.v("idle state", "CALL_STATE_IDLE");
// CALL_STATE_IDLE ( OpenMissedCallScreen )
if (ring == true && callReceived == false && CheckMissCall.isRunning== false) {
flag = true;
if (prefs.getBoolean("main_state", true))
{
Intent inter = new Intent(c, MissCall.class);
}
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// CALL_STATE_OFFHOOK ( OpenReceivedCallScreen )
callReceived = true;
break;
case TelephonyManager.CALL_STATE_RINGING:
ring = true;
// CALL_STATE_RINGING ( openIncomingCallScreen )
break;