public override async void OnReceive(Context context, Intent intent) { try { var requestSerialize = intent.GetStringExtra(NotificationCenter.ReturnRequest); if (string.IsNullOrWhiteSpace(requestSerialize)) { System.Diagnostics.Debug.WriteLine("Request Json Not Found"); return; } var notification = NotificationCenter.GetRequest(requestSerialize); if (notification is null) { System.Diagnostics.Debug.WriteLine("Request Not Found"); return; } if (notification.Schedule.NotifyTime.HasValue && notification.Schedule.RepeatType != NotificationRepeat.No) { var notificationService = TryGetDefaultDroidNotificationService(); if (notification.Schedule.NotifyAutoCancelTime.HasValue && notification.Schedule.NotifyAutoCancelTime <= DateTime.Now) { notificationService.Cancel(notification.NotificationId); System.Diagnostics.Debug.WriteLine("Notification Auto Canceled"); return; } } notification.Schedule.RepeatType = NotificationRepeat.No; // To be consistent with iOS, Do not show notification if NotifyTime is earlier than DateTime.Now //if (notification.Schedule.NotifyTime != null && // notification.Schedule.NotifyTime.Value <= DateTime.Now.AddMinutes(-1)) //{ // System.Diagnostics.Debug.WriteLine("NotifyTime is earlier than DateTime.Now, notification ignored"); // return; //} notification.Schedule.NotifyTime = null; await NotificationCenter.Current.Show(notification); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="intent"></param> public override void OnReceive(Context context, Intent intent) { try { if (intent.Action != EntryIntentAction) { System.Diagnostics.Debug.WriteLine("Action Key Not found"); return; } if (intent.HasExtra(NotificationActionActionId) == false) { System.Diagnostics.Debug.WriteLine("Action Id Key Not found"); return; } if (intent.HasExtra(NotificationCenter.ReturnRequest) == false) { System.Diagnostics.Debug.WriteLine("Request Key Not found"); return; } var actionId = intent.GetIntExtra(NotificationActionActionId, -1000); if (actionId == -1000) { System.Diagnostics.Debug.WriteLine("Action Id Not found"); return; } var requestSerialize = intent.GetStringExtra(NotificationCenter.ReturnRequest); var request = NotificationCenter.GetRequest(requestSerialize); var actionArgs = new NotificationActionEventArgs { ActionId = actionId, Request = request }; var notificationService = TryGetDefaultDroidNotificationService(); notificationService.OnNotificationActionTapped(actionArgs); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }
private NotificationRequest GetRequest(UNNotification notification) { var notificationContent = notification?.Request.Content; if (notificationContent == null) { return(null); } var dictionary = notificationContent.UserInfo; if (!dictionary.ContainsKey(new NSString(NotificationCenter.ReturnRequest))) { return(null); } var requestSerialize = dictionary[NotificationCenter.ReturnRequest].ToString(); var request = NotificationCenter.GetRequest(requestSerialize); return(request); }