Xamarin.Android Notifications on a schedule
I’ve seen people having trouble with scheduling notifications in Xamarin.Android using the Java.Util.Calendar so I made a sample project on Github. Basically the main problem was using ElapsedRealtime instead of Rtc. This app will start the notifications at a specified time and will repeat them every minute, even if the devices is rebooted.
1 2 3 4 5 6 7 |
Intent alarmIntent = new Intent(this, typeof(AlarmReceiver)); PendingIntent pending = PendingIntent.GetBroadcast(this, 0, alarmIntent, PendingIntentFlags.UpdateCurrent); AlarmManager alarmManager = GetSystemService(AlarmService).JavaCast<AlarmManager>(); //AlarmType.RtcWakeup – it will fire up the pending intent at a specified time, waking up the device alarmManager.SetRepeating(AlarmType.RtcWakeup, BootReceiver.FirstReminder(), BootReceiver.reminderInterval, pending); PendingIntent pendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent, 0); |
In MainActivity…
Details