当你有没有打电话给你是IDLE
状态,当你得到一个呼叫它去OFFHOOK
状态 ,当你再次调用结束它去IDLE
状态
更多信息请参考 这
How to know whether I am in a call on Android?
Ë DIT:
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// Toast.makeText(context, "Idle", Toast.LENGTH_LONG).show();
if(UDF.phoneState != TelephonyManager.CALL_STATE_IDLE) {
//Here you are came from offhook because value of UDF.phoneState != TelephonyManager.CALL_STATE_IDLE
//IDLE is calls many times so you have to keep track by a static variable like UDF.phoneState
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Toast.makeText(context, "Idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
//Toast.makeText(context, "Idle", Toast.LENGTH_LONG).show();
endCallIfBlocked(incomingNumber);
break;
default:
break;
}
UDF.phoneState = state;
}
我知道,问题是我试图在手机中进行更改。当状态为OFF_HOOK时它的工作,以及当该电话改回IDLE时它不工作。我试图将代码更改为您发送的链接中的代码,但仍然存在同样的问题。 – ItayM
我编辑了我的答案,如果你有问题,然后告诉我你究竟想要什么 – Dharmendra
@Dharmendra,你只需要在'BroadcastReceiver'中找到手机状态。这就够了。即使你跟踪听众的状态,事情仍然会出错。我的意思是,按照你的方式保持轨道,但在'BroadcastReceiver'中。非常感谢 :-) – 2012-02-14 21:14:57