PhoneStateListener中的传出呼叫检测

时间:2010-12-07 14:50:02

标签: android listener telephonymanager

我想检测android应用程序中的传出呼叫。实际上我可以检测拨出电话,但它也适用于传入,我不希望这样。我需要它只为外向工作。这是我的代码......

boolean ringing = false;
boolean offhook = false;

public void onCallStateChanged(int state, String incomingNumber) {

   switch (state) {


    case TelephonyManager.CALL_STATE_IDLE:

 if((!ringing)&& offhook){
              ///incomming call
         }
          break;
case TelephonyManager.CALL_STATE_RINGING:

    callerPhoneNumber = incomingNumber;
 Log.d(TAG, "RINGING");
 ringing = true;
 offhook = false;     
 break;

   case TelephonyManager.CALL_STATE_OFFHOOK:

 Log.d(TAG, "OFFHOOK");
 offhook = true;
 ringing = false;
 break;
}

1 个答案:

答案 0 :(得分:6)

您可以为android.intent.action.NEW_OUTGOING_CALL编写广播接收器。

See here示例代码可用