title: xamarin.forms call hung up event using android telephony
body: <p>In my xamarin.forms app , I am accessing android telephony API.In my app, user can make call from a button click. I created a broadcast receiver and provided the PhoneStateListener inside the OnReceive. I called the broadcast receiver from my shared code at the time of calling. However the <strong>CallState.Idle</strong> will call at  the first time. I added a messeging center at the CallState.Idle. But the problem is it will call at the time of Broad cast receiver call. What I want is the CallState.Idle event at call hung up. How to achieve this?</p>
  
  <p><strong>My Main Actvity with Broadcast Receiver.</strong></p>
  
  <pre><code>   [BroadcastReceiver(Name = "com.companyname.SampleOutgoingcall.OutgoingCallBroadcastReceiver")]
          [IntentFilter(new[] { Intent.ActionNewOutgoingCall, TelephonyManager.ActionPhoneStateChanged })]
  
          public class OutgoingCallBroadcastReceiver : BroadcastReceiver
          {
              public int READ_CALL_LOG { get; private set; }
  
              public override void OnReceive(Context context, Intent intent)
              {
                  StateListener phoneStateListener = new StateListener();
                  TelephonyManager telephonyManager = (TelephonyManager)context.GetSystemService(TelephonyService);
                  telephonyManager.Listen(phoneStateListener, PhoneStateListenerFlags.CallState);
              }
          }
  
  
  
          public class StateListener : PhoneStateListener
          {
              public override void OnCallStateChanged(CallState state, string incomingNumber)
              {
  
                  base.OnCallStateChanged(state, incomingNumber);
                  switch (state)
                  {
                      case CallState.Ringing:
                          break;
                      case CallState.Offhook:
  
                          try
                          {
                              MessagingCenter.Send&lt;Object&gt;(new Object(), "CallAndroidRinging");
                          }
                          catch (Exception ex)
                          {
                          }
                          break;
                      case CallState.Idle:
  // Trying to get the call hung up event
                          try
                          {
                              MessagingCenter.Send&lt;Object&gt;(new Object(), "CallEndedAndroid");
                          }
                          catch (Exception ex)
                          {
                          }
                          break;
                  }
              }
  
          }
  </code></pre>
  
  <p><strong>My shared code which will call Broadcast Receiver on call.</strong></p>
  
  <pre><code>DependencyService.Get&lt;OutgoingcallTrack&gt;().Send(phonenumber.Text);
  </code></pre>
  
  <p><strong>My interface</strong></p>
  
  <pre><code>namespace SampleOutgoingcall
  {
     public interface OutgoingcallTrack
      {
          void Send(string text);
  
      }
  }
  </code></pre>
  
  <p><strong>My android class</strong></p>
  
  <pre><code>[assembly: Dependency(typeof(OutgoingCall))]
  namespace SampleOutgoingcall.Droid
  {
      class OutgoingCall : OutgoingcallTrack
      {
          public void Send(string text)
          {
              Intent intent = new Intent("com.companyname.SampleOutgoingcall.OutgoingCallBroadcastReceiver");        
              Forms.Context.SendBroadcast(intent);
          }
      }
  }
  </code></pre>