/// <inheritdoc />
        public bool Cancel(params int[] notificationIdList)
        {
            try
            {
                if (Build.VERSION.SdkInt < BuildVersionCodes.IceCreamSandwich)
                {
                    return(false);
                }

                foreach (var notificationId in notificationIdList)
                {
                    var intent      = new Intent(Application.Context, typeof(ScheduledAlarmReceiver));
                    var alarmIntent = PendingIntent.GetBroadcast(
                        Application.Context,
                        notificationId,
                        intent,
                        PendingIntentFlags.CancelCurrent
                        );

                    MyAlarmManager?.Cancel(alarmIntent);
                    MyNotificationManager?.Cancel(notificationId);
                }
                RemovePreferencesNotificationId(PreferencesPendingIdListKey, notificationIdList);
                RemovePreferencesNotificationId(PreferencesDeliveredIdListKey, notificationIdList);
                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(false);
            }
        }
Exemple #2
0
        public void CancelAlarm()
        {
            Analytics.TrackEvent("CancelAlarm in the AlarmForegroundService");
            AlarmManager  alarmManager  = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);
            Intent        intent        = new Intent(Application.Context, typeof(AlarmActivity));
            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);

            alarmManager?.Cancel(pendingIntent);
        }
        public static void StartPushService()
        {
            AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
            {
                PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
                AlarmManager  alarm   = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
                alarm.Cancel(pintent);
            }
        }
        private static void cancelExistingPendingIntentIfNecessary(int notificationId, Intent scheduledNotificationIntent, AlarmManager alarmManager)
        {
            var oldIntent = PendingIntent.GetBroadcast(Application.Context, notificationId, scheduledNotificationIntent, PendingIntentFlags.NoCreate);

            if (oldIntent == null)
            {
                return;
            }

            alarmManager.Cancel(oldIntent);
        }
Exemple #5
0
        public void CancelAlarm()
        {
            Intent i = new Intent(context, typeof(Alarm_Triggered));

            i.PutExtra("ID", ID);
            i.SetPackage(context.PackageName);

            PendingIntent pIntent  = PendingIntent.GetActivity(context.ApplicationContext, int.Parse(ID), i, PendingIntentFlags.OneShot);
            AlarmManager  aManager = (AlarmManager)context.ApplicationContext.GetSystemService(SleepControl.MainActivity.AlarmService);

            aManager.Cancel(pIntent);
        }
        private void CancelAlarms(Context context)
        {
            // Cancel alarm if dependent features are turned off
            if (!ComplicationsExist)
            {
                AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService);
                am.Cancel(GetAlarmIntent(context));
                alarmStarted = false;

                Logger.WriteLine(LoggerLevel.Info, "{0}: Canceled alarm", TAG);
            }
        }
        private void BtnStopAlarm_Click(object sender, EventArgs e)
        {
            PendingIntent pIntent = PendingIntent.GetBroadcast(Application.Context, 0, new Intent(Android.App.Application.Context, typeof(AlarmReceiver)), 0);

            AlarmManager _alarmManager = (AlarmManager)Android.App.Application.Context.GetSystemService(AlarmService);

            _alarmManager.Cancel(pIntent);
            Intent alarmService = new Intent(this, typeof(AlarmTestService));

            StopService(alarmService);
            Toast.MakeText(this, "定时任务被取消", ToastLength.Short).Show();
        }
        /**
         * 기존 등록되어있는 알람을 해제한다.
         */
        private void unregisterRestartAlarm()
        {
            Log.Info("PersistentService", "unregisterRestartAlarm()");
            Intent intent = new Intent(this, typeof(BootReceiver));

            intent.SetAction(BootReceiver.ACTION_RESTART_UPALARMSERVICE);
            PendingIntent sender = PendingIntent.GetBroadcast(ApplicationContext, 0, intent, 0);

            AlarmManager am = (AlarmManager)GetSystemService(AlarmService);

            am.Cancel(sender);
        }
        public void CancelNotification(int id)
        {
            Intent        alarmIntent   = new Intent(Android.App.Application.Context, typeof(AlarmReceiver));
            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Android.App.Application.Context, id, alarmIntent, PendingIntentFlags.UpdateCurrent);
            AlarmManager  alarmManager  = (AlarmManager)Android.App.Application.Context.GetSystemService(Context.AlarmService);

            alarmManager.Cancel(pendingIntent);
            var notificationManager = NotificationManagerCompat.From(Android.App.Application.Context);

            //notificationManager.CancelAll();
            notificationManager.Cancel(id);
        }
        // Runs when last widget is deleted
        public override void OnDisabled(Context context)
        {
            // Cancel autoupdates
            Intent intent = new Intent(context, typeof(ReittiWidget));

            intent.SetAction(UpdateAllWidgets);
            PendingIntent pIntent = PendingIntent.GetBroadcast(context, 0, intent, 0);

            AlarmManager alarmManager = (AlarmManager)context.GetSystemService(Context.AlarmService);

            alarmManager.Cancel(pIntent);
        }
        /// <inheritdoc />
        public void Cancel(int notificationId)
        {
            try
            {
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    _jobScheduler.Cancel(notificationId);
                }
                else
                {
                    var notificationIntent = new Intent(Application.Context, typeof(ScheduledNotificationReceiver));
                    var pendingIntent      = PendingIntent.GetBroadcast(Application.Context, 0, notificationIntent, PendingIntentFlags.CancelCurrent);

                    _alarmManager.Cancel(pendingIntent);
                }
                _notificationManager.Cancel(notificationId);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Exemple #12
0
 protected override void UnscheduleCallbackPlatformSpecific(string callbackId)
 {
     lock (_callbackIdPendingIntent)
     {
         PendingIntent callbackPendingIntent;
         if (_callbackIdPendingIntent.TryGetValue(callbackId, out callbackPendingIntent))
         {
             AlarmManager alarmManager = _service.GetSystemService(global::Android.Content.Context.AlarmService) as AlarmManager;
             alarmManager.Cancel(callbackPendingIntent);
             _callbackIdPendingIntent.Remove(callbackId);
         }
     }
 }
        public void CancelAlarm(AppModels.UserCondition condition)
        {
            Context      context = Xamarin.Forms.Forms.Context;
            AlarmManager am      = (AlarmManager)context.GetSystemService(Context.AlarmService);
            Intent       intent  = new Intent(context, this.Class);

            intent.PutExtra("conditionId", condition.Id);
            intent.PutExtra("conditionName", condition.Condition);

            PendingIntent pi = PendingIntent.GetBroadcast(context, condition.Id, intent, 0);

            am.Cancel(pi);
        }
        public static void StopPushService()
        {
            var context = GlobalSettings.GetContext;

            context.StopService(new Intent(GlobalSettings.GetContext, typeof(PushNotificationService)));

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
            {
                PendingIntent pintent = PendingIntent.GetService(GlobalSettings.GetContext, 0, new Intent(context, typeof(PushNotificationService)), 0);
                AlarmManager  alarm   = (AlarmManager)context.GetSystemService(Context.AlarmService);
                alarm.Cancel(pintent);
            }
        }
Exemple #15
0
        public void deleteNotification(ReminderDataStructure r)
        {
            Intent alarmIntent = new Intent(Forms.Context, typeof(AlarmReciver));

            alarmIntent.PutExtra("message", r.Description);
            alarmIntent.PutExtra("title", r.Title);
            alarmIntent.PutExtra("id", r.Id);

            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Forms.Context, r.Id, alarmIntent, PendingIntentFlags.UpdateCurrent);
            AlarmManager  alarmManager  = (AlarmManager)Forms.Context.GetSystemService(Context.AlarmService);

            alarmManager.Cancel(pendingIntent);
        }
        public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
        {
            //Killswitch to decide if user wants to stop downloading images.
            //Stop All receivers, alarms, etc.
            if (key == ConfigurationParameters.EnableService)
            {
                if (sharedPreferences.GetBoolean(key, false) == true)
                {
                    #region Enable AlarmManager Ice Cream Sandwich.

                    if (Build.VERSION.SdkInt < BuildVersionCodes.KitkatWatch)
                    {
                        intent        = new Intent(Application.Context, typeof(AlarmReceiver));
                        pendingIntent = PendingIntent.GetBroadcast(Application.Context, 2, intent, PendingIntentFlags.UpdateCurrent);
                        //If the user enables the service, schedule the alarm or Scheduler to download data each day.
                        EnableBootReceiver();

                        //Kitkat or Less.
                        //>Schedule an alarm to run after 30 minutes after this call(second parameter), and once a day after that.(third parameter)
                        alarmManager.SetInexactRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + AlarmManager.IntervalFifteenMinutes, AlarmManager.IntervalDay, pendingIntent);
                    }

                    #endregion Enable AlarmManager Ice Cream Sandwich.

                    #region Enable JobScheduler Lollipop and Beyond.

                    Scheduler.ScheduleJob(Application.Context);

                    #endregion Enable JobScheduler Lollipop and Beyond.
                }
                else if (sharedPreferences.GetBoolean(key, false) == false)
                {
                    #region Disable AlarmManager Ice Cream Sandwich

                    if (Build.VERSION.SdkInt < BuildVersionCodes.KitkatWatch)
                    {
                        alarmManager?.Cancel(pendingIntent);
                        DisableBootReceiver();
                    }

                    #endregion Disable AlarmManager Ice Cream Sandwich

                    #region Disable JobScheduler Lollipop and Beyond.

                    Scheduler.CancelSchedule(Application.Context);

                    #endregion Disable JobScheduler Lollipop and Beyond.
                }
            }
        }
Exemple #17
0
        public void Cancel(int id)
        {
            Intent        intent        = CreateIntent(id);
            PendingIntent pendingIntent =
                PendingIntent.GetBroadcast(AndroidApp.Context, 0, intent, PendingIntentFlags.CancelCurrent);

            AlarmManager alarmManager = GetAlarmManager();

            alarmManager.Cancel(pendingIntent);

            NotificationManagerCompat notificationManager = NotificationManagerCompat.From(AndroidApp.Context);

            notificationManager.Cancel(id);
        }
Exemple #18
0
        public void CancelingNotification(string Title, string Subtitle, string Body, string requestID, DateTime inputDate, Page page)
        {
            Intent alarmIntent = new Intent(Forms.Context, typeof(AlarmReceiver));

            alarmIntent.PutExtra("message", Body);
            alarmIntent.PutExtra("title", Title);
            alarmIntent.PutExtra("id", requestID);
            alarmIntent.PutExtra("date", inputDate.ToString());

            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Forms.Context, int.Parse(requestID), alarmIntent, PendingIntentFlags.UpdateCurrent);
            AlarmManager  alarmManager  = (AlarmManager)Forms.Context.GetSystemService(Context.AlarmService);

            alarmManager.Cancel(pendingIntent);
        }
Exemple #19
0
 public void cancelAlarm()   //zatrzymanie usługi
 {
     try
     {
         Intent        intent  = new Intent(Application.Context, typeof(MyAlarmReceiver));
         PendingIntent pIntent = PendingIntent.GetBroadcast(this, MyAlarmReceiver.REQUEST_CODE, intent, PendingIntentFlags.UpdateCurrent);
         AlarmManager  alarm   = (AlarmManager)this.GetSystemService(Context.AlarmService);
         alarm.Cancel(pIntent);
     }
     catch (Exception ex)
     {
         logger.createLog("Application error: " + ex.Message, "ErrorLogs.txt");
     }
 }
            public static void StopNotification()
            {
                if (Main == null)
                {
                    Console.WriteLine("Can't stop notifications because of null in MainActivity.");
                    return;
                }
                Context       context       = Main as Context;
                Intent        myIntent      = new Intent(context, typeof(AlarmNotificationReceiver));
                PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, myIntent, 0);
                AlarmManager  manager       = (AlarmManager)Main.GetSystemService(Context.AlarmService);

                manager.Cancel(pendingIntent);
            }
Exemple #21
0
        private void showPopupMenu(int i)
        {
            PopupMenu popupMenu = new PopupMenu(this, button);

            popupMenu.Inflate(Resource.Menu.popupmenu);
            popupMenu.MenuItemClick += (sender, e) =>
            {
                int indexIndent = calendar.SelectedDate.Day * 1000000 + calendar.SelectedDate.Month * 10000 + calendar.SelectedDate.Year;
                var alarmIntent = new Intent(this, typeof(Alarm));
                var pending     = PendingIntent.GetBroadcast(this, indexIndent, alarmIntent, PendingIntentFlags.UpdateCurrent);
                am.Cancel(pending);
                if (e.Item.TitleFormatted.ToString() == "Удалить")
                {
                    records.RemoveAt(i);
                    ViewModel.deleteRecord(i);
                    ViewModel.setSoonView();
                    if (ViewModel.record != null)
                    {
                        SoonViewName.Text = ViewModel.record.Name;
                        string b = ":";
                        if (ViewModel.record.Min < 10)
                        {
                            b = ":0";
                        }
                        SoonViewTime.Text = ViewModel.record.RecordDate + " " + ViewModel.record.Hour + b + ViewModel.record.Min;
                        SoonViewMore.Text = ViewModel.record.More;
                    }
                    if (ViewModel.getRecordsCount() == 0)
                    {
                        SoonViewName.Text = "";
                        SoonViewTime.Text = "";
                        SoonViewMore.Text = "";
                    }
                }
                else
                {
                    ViewModel.setRecordObject(i);
                    ViewModel.MyButtonCommand1.Execute();
                }
            };

            popupMenu.DismissEvent += (sender, e) =>
            {
                calendar.Selected = false;
                Console.WriteLine("menu dismissed");
            };

            popupMenu.Show();
        }
        public override void OnDestroy()
        {
            base.OnDestroy();

            // Create widget update intent
            Intent intent = new Intent();

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            PendingIntent pendingIntent = PendingIntent.GetBroadcast(this, 0, intent, 0);

            // Cancel the pending intent
            AlarmManager alarmManager = GetSystemService(AlarmService) as AlarmManager;

            alarmManager.Cancel(pendingIntent);
        }
Exemple #23
0
        protected override void CancelLocalInvocation(ScheduledCallback callback)
        {
            // we don't need a reference to the original pending intent in order to cancel the alarm. we just need a pending intent
            // with the same request code and underlying intent with the same action. extras are not considered, and we don't use
            // the other intent fields (data, categories, etc.). see the following for more information:
            //
            // https://developer.android.com/reference/android/app/PendingIntent.html
            //
            Intent        callbackIntent        = CreateCallbackIntent(callback);
            PendingIntent callbackPendingIntent = CreateCallbackPendingIntent(callbackIntent);
            AlarmManager  alarmManager          = _service.GetSystemService(global::Android.Content.Context.AlarmService) as AlarmManager;

            alarmManager.Cancel(callbackPendingIntent);
            SensusServiceHelper.Get().Logger.Log("Unscheduled alarm for callback " + callback.Id + ".", LoggingLevel.Normal, GetType());
        }
        /// <summary>
        /// Cancels the scheduled alarm.
        /// </summary>
        /// <returns>The alarm to be canceled.</returns>
        /// <param name="alarm">Alarm.</param>
        public void CancelAlarm(Alarm alarm)
        {
            var           intent = new Intent(context, typeof(AlarmIntentService));
            PendingIntent pendingIntent;

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                pendingIntent = PendingIntent.GetForegroundService(context, alarm.Id, intent, PendingIntentFlags.UpdateCurrent);
            }
            else
            {
                pendingIntent = PendingIntent.GetService(context, alarm.Id, intent, PendingIntentFlags.UpdateCurrent);
            }

            alarmManager.Cancel(pendingIntent);
        }
        public void SetNotification()
        {
            Intent alarmIntent = new Intent(this, typeof(AlarmReceiver));

            PendingIntent pendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent, PendingIntentFlags.UpdateCurrent);
            AlarmManager  alarmManager  = (AlarmManager)this.GetSystemService(Context.AlarmService);

            if (prefEnableNotifications)
            {
                alarmManager.SetRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime(), millisecondsNotifications, pendingIntent);
            }
            else
            {
                alarmManager.Cancel(pendingIntent);
            }
        }
Exemple #26
0
        public void cancelAlarm(Context context)
        {
            // If the alarm has been set, cancel it.
            if (am != null)
            {
                am.Cancel(pi);
            }

            // Disable {@code SampleBootReceiver} so that it doesn't automatically restart the
            // alarm when the device is rebooted.
            ComponentName  receiver = new ComponentName(context, Java.Lang.Class.FromType(typeof(SampleBootReceiver)));
            PackageManager pm       = context.PackageManager;

            pm.SetComponentEnabledSetting(receiver,
                                          ComponentEnabledState.Disabled,
                                          ComponentEnableOption.DontKillApp);
        }
 private void FabOnClick(object sender, EventArgs eventArgs)
 {
     if (!_scheduleRunning)
     {
         //Starting the scheduled task
         _alarm = (AlarmManager)GetSystemService(AlarmService);
         _alarm.SetRepeating(AlarmType.RtcWakeup, DateTime.Now.TimeOfDay.Milliseconds, _interval, _pendingIntent);
         Toast.MakeText(this, "Schedule started", ToastLength.Short).Show();
     }
     else
     {
         if (_alarm != null)
         {
             _alarm.Cancel(_pendingIntent);
             Toast.MakeText(this, "Schedule stopped", ToastLength.Short).Show();
         }
     }
 }
Exemple #28
0
        public bool RemoveAlarm(Reminder reminder)
        {
            Context      context      = Android.App.Application.Context;
            AlarmManager alarmManager = context.GetSystemService(Context.AlarmService) as AlarmManager;
            Intent       intent       = new Intent(context, typeof(Services.RingtoneService));

            intent.PutExtra("Title", reminder.Name);
            context.StopService(intent);

            PendingIntent pendingIntent = PendingIntent.GetService(
                context, reminder.ReminderId, intent, 0);


            alarmManager.Cancel(pendingIntent);

            WriteLine($"Alarm Removed {reminder.Name}, {reminder.ReminderId}");
            return(true);
        }
Exemple #29
0
 public Alert RemoveTimeNotification(Alert alert)
 {
     try
     {
         Intent        intent    = new Intent(Android.App.Application.Context, typeof(NotificationSender));
         PendingIntent broadcast = PendingIntent.GetBroadcast(Android.App.Application.Context,
                                                              alert.Id,
                                                              intent,
                                                              PendingIntentFlags.UpdateCurrent);
         AlarmManager alarmManager = (AlarmManager)Android.App.Application.Context.GetSystemService(AlarmService);
         alarmManager.Cancel(broadcast);
         return(alert);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemple #30
0
        public static void SetServiceAlarm(Context context, bool isOn)
        {
            Intent        i  = new Intent(context, typeof(PollService));
            PendingIntent pi = PendingIntent.GetService(context, 0, i, 0);

            AlarmManager alarmManager = (AlarmManager)context.GetSystemService(Context.AlarmService);

            if (isOn)
            {
                alarmManager.SetRepeating(AlarmType.Rtc, DateTime.Now.Millisecond, POLL_INTERVAL, pi);
            }
            else
            {
                alarmManager.Cancel(pi);
                pi.Cancel();
            }

            PreferenceManager.GetDefaultSharedPreferences(context).Edit().PutBoolean(PollService.PREF_IS_ALARM_ON, isOn).Commit();
        }