且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PhoneStateListener呼出检测

更新时间:2023-12-02 17:15:34

您可以写一个广播接收器 android.intent.action.NEW_OUTGOING_CALL

看到这里样品code是可用

I want to detect outgoing call in android application . Actually I can detect outgoing calls but it is also working for incoming too and I don't want that. I need it to work only for outgoing. here is my code....

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;
}

You can write a broadcast receiver for android.intent.action.NEW_OUTGOING_CALL.

See here Sample code is available