开发者

outgoing call detect in PhoneStateListener

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜