Skip to content Skip to sidebar Skip to footer

How To Get Event When I Am Answering Outgoing Call

Can you help me to understand how to detect whether the outgoing call is answered or not ( I need to record call starting from answer till dropping)? I can detect it for incoming c

Solution 1:

Use TelephonyManager.ActionPhoneStateChanged to monitor the TelephonyManager state, upon receiving TelephonyManager.ExtraStateIdle you know when phone radio is now idling (no call in process).

Inbound & Outbound BroadcastReceiver Example:

[BroadcastReceiver(Name = "com.sushhangover.OutgoingCallBroadcastReceiver")]
[IntentFilter(new[] { Intent.ActionNewOutgoingCall, TelephonyManager.ActionPhoneStateChanged })]
publicclassOutgoingCallBroadcastReceiver : BroadcastReceiver
{
    publicoverridevoidOnReceive(Context context, Intent intent)
    {
        switch (intent.Action)
        {
            case Intent.ActionNewOutgoingCall:
                var outboundPhoneNumber = intent.GetStringExtra(Intent.ExtraPhoneNumber);
                Toast.MakeText(context, $"Started: Outgoing Call to {outboundPhoneNumber}", ToastLength.Long).Show();
                break;
            case TelephonyManager.ActionPhoneStateChanged:
                var state = intent.GetStringExtra(TelephonyManager.ExtraState);
                if (state == TelephonyManager.ExtraStateIdle)
                    Toast.MakeText(context, "Phone Idle (call ended)", ToastLength.Long).Show();
                elseif (state == TelephonyManager.ExtraStateOffhook)
                    Toast.MakeText(context, "Phone Off Hook", ToastLength.Long).Show();
                elseif (state == TelephonyManager.ExtraStateRinging)
                    Toast.MakeText(context, "Phone Ringing", ToastLength.Long).Show();
                elseif (state == TelephonyManager.ExtraIncomingNumber)
                {
                    var incomingPhoneNumber = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);
                    Toast.MakeText(context, $"Incoming Number: {incomingPhoneNumber}", ToastLength.Long).Show();
                }
                break;
            default:
                break;
        }
    }
}

Note: Make sure you add permissions to ReadPhoneState and ProcessOutgoingCalls for this example to work.

Post a Comment for "How To Get Event When I Am Answering Outgoing Call"