title: WakefulBroadcastReceiver Xamarin Does not work
body: <p>I wrote a program, for when sms received it will play ring. But it's work only when program is running and when program closed it's doesn't work.</p>
  
  <p>What should I do? </p>
  
  <pre><code>public class MainActivity : Activity
  {
      SampleReceiver receiver;
  
      protected override void OnCreate(Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);
  
          // Set our view from the "main" layout resource
          SetContentView(Resource.Layout.Main);
  
          receiver = new SampleReceiver();
  
          IntentFilter intentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
          intentFilter.Priority = 1000;
  
          RegisterReceiver(receiver, intentFilter);
  
          // Code omitted for clarity
      }
  
  
  }
  
  [BroadcastReceiver(Enabled = true, Exported = true)]
  public class SampleReceiver : WakefulBroadcastReceiver
  {
  
      private const string IntentAction = "android.provider.Telephony.SMS_RECEIVED";
      public override void OnReceive(Context context, Intent intent)
      {
          try
          {
              Android.Net.Uri uri = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);
              Ringtone ringtone = RingtoneManager.GetRingtone(context, uri);
              ringtone.Play();
  
              if (intent.HasExtra("pdus"))
              {
                  var smsArray = (Java.Lang.Object[])intent.Extras.Get("pdus");
  
                  foreach (var item in smsArray)
                  {
                      var sms = SmsMessage.CreateFromPdu((byte[])item);
                      string address = sms.OriginatingAddress;
                      string smsText = sms.MessageBody;
  
                      Toast.MakeText(context, "Massage from : " + address + " Says : " + smsText, ToastLength.Long).Show();
                  }
              }
  
  
          }
          catch (System.Exception ex)
          {
              //Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
          }
      }
  }
  </code></pre>
  
  <p>Tnx </p>