private async Task cancelPendingIntentsForMedicationSchedule()//List<MedicationSchedule> _medications
        {
            Log.Error(Log_Tag, "start canceling pi");
            NetworkingData            networking = new NetworkingData();
            List <MedicationSchedule> list       = new List <MedicationSchedule>(await networking.ReadListFromDbFutureDataTask());


            foreach (MedicationSchedule item in list)
            {
                Log.Error(Log_Tag, "canceling pi .. " + item.IdNotification);
                var           am     = (AlarmManager)Application.Context.GetSystemService(AlarmService);
                var           intent = new Intent(BaseContext, typeof(AlarmBroadcastReceiverServer));
                PendingIntent pi     = PendingIntent.GetBroadcast(Application.Context, item.IdNotification, intent, 0);
                //pi.Cancel();

                if (pi == null)
                {
                    Log.Error(Log_Tag, "pi is null");
                }
                else
                {
                    Log.Error(Log_Tag, "pi is not null");
                }

                am.Cancel(pi);
                pi.Cancel();
                // networking.removeMedSer(item.Uuid);
            }
        }
Ejemplo n.º 2
0
        private async Task cancelPendingIntentsForMedicationSchedule()
        {
            Log.Error("MainActivity", "start canceling pending intents");
            try {
                NetworkingData            networking = new NetworkingData();
                List <MedicationSchedule> list       = new List <MedicationSchedule>(await networking.ReadListFromDbFutureDataTask());
                var am = (AlarmManager)Application.Context.GetSystemService(AlarmService);

                foreach (MedicationSchedule item in list)
                {
                    Log.Error("MainActivity", "canceling pi .. " + item.IdNotification);
                    var           intent = new Intent(Application.Context, typeof(AlarmBroadcastReceiverServer));
                    PendingIntent pi     = PendingIntent.GetBroadcast(Application.Context, item.IdNotification, intent, 0);

                    if (pi == null)
                    {
                        Log.Error("MainActivity", "pi is null");
                    }
                    else
                    {
                        Log.Error("MainActivity", "pi is not null");
                    }

                    //pi.Cancel();
                    am.Cancel(pi);
                    pi.Cancel();
                    //networking.removeMedSer(item.Uuid);
                }

                Log.Error("MainActivity", "finish canceling pending intents");
            } catch (Exception e) {
                Log.Error("MainActivity", "canceling pi ERROR" + e.Message);
            }
        }
            public void Dispose()
            {
                var am = AlarmManager.FromContext(Application.Context);

                am?.Cancel(pendingIntent);
                pendingIntent.Cancel();
            }
        private void StopPinging()
        {
            var alarmManager = (AlarmManager)master_service.GetSystemService(Context.AlarmService);

            alarmManager.Cancel(repeating_pending_intent);
            repeating_pending_intent.Cancel();

            repeating_pending_intent = null;
        }
Ejemplo n.º 5
0
        public void StopLocationUpdates()
        {
            PendingIntent pi = GetLocationPendingIntent(false);

            if (pi != null)
            {
                mLocationManager.RemoveUpdates(pi);
                pi.Cancel();
            }
        }
Ejemplo n.º 6
0
        private void CancelAlarm(Alarm alarm, AlarmManager alarmManager, Intent alarmIntent)
        {
            int baseID = GetFirstID(alarm);

            for (int i = 0; i < alarm.AllTimes.Count; i++)
            {
                PendingIntent pendingIntent = PendingIntent.GetBroadcast(Android.App.Application.Context, baseID + i, alarmIntent, PendingIntentFlags.UpdateCurrent);
                pendingIntent.Cancel();
            }
        }
        public static void CancelWakeUpAlarmRepeating(Context context)
        {
            AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService);

            if (pendingIntent != null)
            {
                am.Cancel(pendingIntent);
                pendingIntent.Cancel();
            }
        }
Ejemplo n.º 8
0
        public void CancelAlarm()
        {
            AlarmManager alarmManager = (AlarmManager)Activity.GetSystemService(Context.AlarmService);
            Intent       intent       = new Intent(Activity, typeof(AlarmReceiver));

            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Activity, /*a traves del anterior id ahora podemos pedir que se actualice */ 0, intent, PendingIntentFlags.UpdateCurrent);

            //Con el pending intent actualizado podemos cancelarlo
            pendingIntent.Cancel();
            alarmManager.Cancel(pendingIntent);
        }
Ejemplo n.º 9
0
 public void StopAlarm(int req)
 {
     if (alarmManager == null)
     {
         return;
     }
     intent        = new Intent(context, typeof(AlarmReceiver));
     pendingIntent = PendingIntent.GetBroadcast(context, req, intent, PendingIntentFlags.UpdateCurrent);
     pendingIntent.Cancel();
     alarmManager.Cancel(pendingIntent);
 }
Ejemplo n.º 10
0
        private static void CancelAlarms(Context context)
        {
            var           am              = (AlarmManager)context.GetSystemService(Context.AlarmService);
            var           intent          = new Intent(Application.Context, typeof(AlarmDeviceReceiver));
            PendingIntent piBloodPressure = PendingIntent.GetBroadcast(Application.Context, Constants.BloodPressureNotifId, intent, 0);
            PendingIntent piGlucose       = PendingIntent.GetBroadcast(Application.Context, Constants.GlucoseNotifId, intent, 0);

            am.Cancel(piBloodPressure);
            piBloodPressure.Cancel();
            am.Cancel(piGlucose);
            piGlucose.Cancel();
        }
Ejemplo n.º 11
0
        public override void OnReceive(Context context, Intent intent)
        {
            // Get extras from broadcast
            String name = intent.GetStringExtra("Name");
            String key  = LocationManager.KeyProximityEntering;

            // Are we entering or exiting the proximity/location
            Boolean entering = intent.GetBooleanExtra(key, false);

            Log.Info("Vegas", "Broadcast Intent Received: " + intent.GetStringExtra("Name"));
            Log.Info("Vegas", "Broadcast Intent Entering? " + entering);

            PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.UpdateCurrent);
            String        notificationText;

            if (entering)
            {
                notificationText = "Welcome to " + name;
                Toast.MakeText(context, notificationText, ToastLength.Short).Show();
            }
            else
            {
                notificationText = "Thank you for visiting " + name;
                Toast.MakeText(context, notificationText, ToastLength.Short).Show();
            }

            // Show notification
            try
            {
                Utilities notificationUtility = new Utilities(context);
                notificationUtility.ShowNotification(notificationText, notificationText, NOTIFICATION_ID, pendingIntent);
            }
            catch (Java.Lang.IllegalArgumentException ex)
            {
                Log.Info("Vegas", "ERROR!!!!! " + ex.Message);
                if (ex.InnerException != null)
                {
                    Log.Info("Vegas", "INNER EXCEPTION!!! " + ex.InnerException);
                }
            }

            PendingIntent proximityIntent = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            proximityIntent.Cancel();
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        public static void StartAlarm(Alarm a, Context context)
        {
            if (a == null)
            {
                return;
            }
            AlarmManager manager = (AlarmManager)context.GetSystemService(Context.AlarmService);
            Intent       i       = new Intent(context, typeof(AlarmReceiver));

            //put sound as extra!!
            Console.WriteLine("alarm started for : " + a.Time.Hours + ":" + a.Time.Minutes);
            i.PutExtra("startAlarm", a);
            if (pendingIntent != null)
            {
                pendingIntent.Cancel();
                //pendingIntent = null;
            }

            pendingIntent = PendingIntent.GetBroadcast(context, 5, i, 0);
            int day = (int)(DateTime.Now.DayOfWeek + 6) % 7;
            int j;

            if (a.Days [day] == true && a.Time > DateTime.Now.TimeOfDay)
            {
                j = day;
            }
            else
            {
                j = day + 1;
                while (a.Days [j % 7] != true && j <= day + 7)
                {
                    j++;
                }
            }

            DateTime alarmDate = DateTime.Today.AddDays(j - day);

            manager.SetExact(AlarmType.RtcWakeup, (long)(Java.Lang.JavaSystem.CurrentTimeMillis() + (new DateTime(alarmDate.Year, alarmDate.Month, alarmDate.Day, a.Time.Hours, a.Time.Minutes, 0).ToUniversalTime() - DateTime.Now.ToUniversalTime()).TotalMilliseconds), pendingIntent);
            Console.WriteLine("Alarm set for " + alarmDate.Day + ", at: " + a.Time.Hours + ":" + a.Time.Minutes + "!");
        }
Ejemplo n.º 14
0
        public AlarmActiveEventArgs StopBirdieLib()
        {
            // Stop the WorkManager.  --Kris
            WorkManager.Instance.CancelAllWork();
            PeriodicWorkRequest = null;

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

            try
            {
                alarmManager.Cancel(pendingIntent);
                pendingIntent.Cancel();
            }
            catch (Exception) { }

            Shared.BirdieLib.Stop();

            return(new AlarmActiveEventArgs
            {
                IsScheduled = false
            });
        }
Ejemplo n.º 15
0
        public INotificationResult Notify(Activity activity, INotificationOptions options)
        {
            var notificationId = _count;
            var id             = _count.ToString();

            _count++;

            Intent dismissIntent = new Intent(DismissedClickIntent);

            dismissIntent.PutExtra(NotificationId, notificationId);

            PendingIntent pendingDismissIntent = PendingIntent.GetBroadcast(activity.ApplicationContext, 123, dismissIntent, 0);

            Intent clickIntent = new Intent(OnClickIntent);

            clickIntent.PutExtra(NotificationId, notificationId);

            // Add custom args
            if (options.CustomArgs != null)
            {
                foreach (var arg in options.CustomArgs)
                {
                    clickIntent.PutExtra(arg.Key, arg.Value);
                }
            }

            PendingIntent pendingClickIntent = PendingIntent.GetBroadcast(activity.ApplicationContext, 123, clickIntent, 0);

            int smallIcon;

            if (options.AndroidOptions.SmallDrawableIcon.HasValue)
            {
                smallIcon = options.AndroidOptions.SmallDrawableIcon.Value;
            }
            else if (_androidOptions.SmallIconDrawable.HasValue)
            {
                smallIcon = _androidOptions.SmallIconDrawable.Value;
            }
            else
            {
                smallIcon = Android.Resource.Drawable.IcDialogInfo; // As last resort
            }
            Android.App.Notification.Builder builder = new Android.App.Notification.Builder(activity)
                                                       .SetContentTitle(options.Title)
                                                       .SetContentText(options.Description)
                                                       .SetSmallIcon(smallIcon)                     // Must have small icon to display
                                                       .SetPriority((int)NotificationPriority.High) // Must be set to High to get Heads-up notification
                                                       .SetDefaults(NotificationDefaults.All)       // Must also include vibrate to get Heads-up notification
                                                       .SetAutoCancel(true)                         // To allow click event to trigger delete Intent
                                                       .SetContentIntent(pendingClickIntent)        // Must have Intent to accept the click
                                                       .SetDeleteIntent(pendingDismissIntent);

            Android.App.Notification notification = builder.Build();

            NotificationManager notificationManager =
                activity.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(notificationId, notification);

            var timer = new Timer(x => TimerFinished(id), null, TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(100));

            var resetEvent = new ManualResetEvent(false);

            ResetEvent.Add(id, resetEvent);

            resetEvent.WaitOne(); // Wait for a result

            var notificationResult = EventResult[id];

            if (!options.IsClickable && notificationResult.Action == NotificationAction.Clicked)
            {
                notificationResult.Action = NotificationAction.Dismissed;
            }

            EventResult.Remove(id);
            ResetEvent.Remove(id);

            // Dispose of Intents and Timer
            pendingClickIntent.Cancel();
            pendingDismissIntent.Cancel();
            timer.Dispose();

            return(notificationResult);
        }
Ejemplo n.º 16
0
 public void CancelTheNotification()
 {
     alarmManager.Cancel(pending);
     pending.Cancel();
 }