Ejemplo n.º 1
0
        public void RemoveScheduledNotification(int id)
        {
            var intent        = NotificationSchedulerReceiver.CreateIntent(id, null, null);
            var pendingIntent = PendingIntent.GetBroadcast(
                Application.Context,
                0,
                intent,
                PendingIntentFlags.CancelCurrent);

            var alarmManager = GetAlarmManager();

            alarmManager.Cancel(pendingIntent);

            var notificationManager = NotificationManagerCompat.From(Application.Context);

            notificationManager.Cancel(id);
        }
Ejemplo n.º 2
0
        public void ScheduleNotification(TaskReminderNotification notification)
        {
            var  now     = DateTimeOffset.Now;
            bool showNow = notification.DeliveryOn <= now;

            if (showNow)
            {
                ShowTaskReminderNotification(notification);
                return;
            }

            var intent = NotificationSchedulerReceiver.CreateIntent(
                notification.Id,
                NotificationSchedulerReceiver.TaskReminderNotificationKey,
                JsonConvert.SerializeObject(notification));

            var pendingIntent = PendingIntent.GetBroadcast(
                Application.Context,
                0,
                intent,
                PendingIntentFlags.CancelCurrent);

            var future       = (long)(notification.DeliveryOn - now).TotalMilliseconds;
            var milis        = Java.Lang.JavaSystem.CurrentTimeMillis() + future;
            var alarmManager = GetAlarmManager();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, milis, pendingIntent);
            }
            else if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
            {
                alarmManager.SetExact(AlarmType.RtcWakeup, milis, pendingIntent);
            }
            else
            {
                alarmManager.Set(AlarmType.RtcWakeup, milis, pendingIntent);
            }
        }