1

I would like to start a timer only if the outgoing call has been answered. Like the default phone app in Nexus 5.

Is there a way to figure if the call has been answered?

I tried the phone listener immediately after the phone number has been dialed it gets to CALL_STATE_OFFHOOK. So this is not the right approach?

Can somebody help me figure this out?

Thanks!

TheDevMan
  • 5,914
  • 12
  • 74
  • 144
  • possible duplicate of [Detect if an outgoing call has been answered](http://stackoverflow.com/questions/2250455/detect-if-an-outgoing-call-has-been-answered) – Sree Apr 01 '14 at 04:29

1 Answers1

0

may this one help you :

public class CallLogReceiver extends BroadcastReceiver {

static boolean missedCall, incomingCall;

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub


    if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
        String state = intent.getExtras().getString(
                TelephonyManager.EXTRA_STATE);

        if ((state != null)
                && (state.equals(TelephonyManager.EXTRA_STATE_RINGING))) {
            CallLogReceiver.phoneNo = intent.getExtras().getString(
                    "incoming_number");
            CallLogReceiver.missedCall = true;
        }

        if ((state != null)
                && (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))) {
            CallLogReceiver.incomingCall = true;

        }
        if (state != null
                && !(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
                && !(state.equals(TelephonyManager.EXTRA_STATE_RINGING))) {

            if (CallLogReceiver.missedCall && CallLogReceiver.incomingCall) {
                //incoming call logic
            }

            else if (CallLogReceiver.missedCall
                    && !CallLogReceiver.incomingCall) {
                // missed call logic
            }
            CallLogReceiver.missedCall = CallLogReceiver.incomingCall = false;
        }
      }
    }
}
Umang Kothari
  • 3,674
  • 27
  • 36
  • I still have the same problem - Immediately after I press the dial it goes to state_OFFHOOK. – TheDevMan Apr 01 '14 at 05:08
  • no there is some problem in your code because when you dial phone number then state goes in EXTRA_STATE_RINGING and when you pick up then state goes in EXTRA_STATE_OFFHOOK...try to debug – Umang Kothari Apr 01 '14 at 05:47