當你有沒有打電話給你是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