Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

StartBroadcast from NotificationAlertReceiver not firing

$
0
0

Hey folks, I a problem. I want do send a Broadcast from my NotificationAlertReceiver. Here's some code i found on the net, which works fine except that the intent is not being sent. `using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Android.Util;

namespace Test_Android { [BroadcastReceiver] class NotificationAlertReceiver : BroadcastReceiver {

    public NotificationAlertReceiver()
    {

    }

    public override void OnReceive(Context context, Intent intent)
    {
        PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
        PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Partial, "NotificationReceiver");
        w1.Acquire ();

        var broadcastIntent = new Intent();
        broadcastIntent.SetAction("com.mypackagename.StartChecking");
        context.SendBroadcast(broadcastIntent);

        Android.Widget.Toast.MakeText (context, "OnReceive", Android.Widget.ToastLength.Short).Show ();


        w1.Release ();
    }

    public void CancelAlarm(Context context){ 
        Intent intent = new Intent(context, this.Class);
        PendingIntent sender = PendingIntent.GetBroadcast (context, 0, intent, 0);
        AlarmManager alarmManager = (AlarmManager) context.GetSystemService (Context.AlarmService);
        alarmManager.Cancel (sender);
    }

    public void SetAlarm(Context context, int alertTime){
        long now = SystemClock.ElapsedRealtime();
        AlarmManager am = (AlarmManager) context.GetSystemService (Context.AlarmService);
        Intent intent = new Intent(context, this.Class);
        PendingIntent pi = PendingIntent.GetBroadcast (context, 0, intent, 0);
        am.Set (AlarmType.ElapsedRealtimeWakeup, now + ((long)(alertTime)), pi);
        //Android.Widget.Toast.MakeText (context, "SetAlarm", Android.Widget.ToastLength.Short).Show ();
    }
}

}`

The toast "OnReceive" is being shown, but the intent is not going out. Any idea on what I'm doing wrong? Help would be really much appreciated. greets xsx


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>