开发者

outgoing call detect in PhoneStateListener

开发者 https://www.devze.com 2023-01-29 21:02 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消