Esempio n. 1
0
 public void UpdateAlert(Alert alert, bool disable)
 {
     if (disable)
     {
         _alertService.DisableAlert(alert);
         DependencyService.Get <INotificationService>().RemoveLocationNotification(alert);
         DependencyService.Get <IToastService>().ShortMessage("Alert disabled");
         Refresh.Execute(null);
     }
     else
     {
         alert.State = AlertState.Pending;
         _alertService.ActivateAlert(alert);
         var location     = _locationService.GetLocationById(alert.LocationID);
         var notification = new LocationNotification
         {
             Id       = alert.Id,
             Title    = alert.Title,
             Body     = alert.Description,
             Position = new Xamarin.Forms.Maps.Position(location.Latitude, location.Longitude),
             Radius   = 30
         };
         DependencyService.Get <INotificationService>().ScheduleLocationNotification(notification);
         DependencyService.Get <IToastService>().ShortMessage("Alert reactivated");
         Refresh.Execute(null);
     }
 }
Esempio n. 2
0
        public LocationNotification ScheduleLocationNotification(LocationNotification locationNotification)
        {
            try
            {
                Intent intent = new Intent(Android.App.Application.Context, typeof(NotificationSender));

                intent.PutExtra("ID", locationNotification.Id);
                intent.PutExtra("Title", locationNotification.Title);
                intent.PutExtra("Body", locationNotification.Body);
                intent.PutExtra("Type", "LocationNotification");

                var latitude  = locationNotification.Position.Latitude;
                var longitude = locationNotification.Position.Longitude;
                var radius    = locationNotification.Radius;

                PendingIntent broadcast = PendingIntent.GetBroadcast(Android.App.Application.Context,
                                                                     locationNotification.Id,
                                                                     intent,
                                                                     PendingIntentFlags.UpdateCurrent);

                LocationManager locationManager = (LocationManager)Android.App.Application.Context.GetSystemService(LocationService);

                locationManager.AddProximityAlert(latitude, longitude, radius, -1, broadcast);

                return(locationNotification);
            }
            catch (Exception)
            {
                return(null);
            }
        }