public void ReceiveSelectedNotification(string title, string message, int notificationId, string selectedAction) { var args = new LocalNotificationEventArgs() { Id = notificationId, Title = title, Message = message, SelectedAction = selectedAction }; NotificationSelectionReceived?.Invoke(null, args); }
public int Notify(string title, string message, int notificationId, NotificationOptions options = null) { messageId++; Log.Debug("Alarm", "AlarmNotificationReceiver Notify MessageId: " + messageId.ToString()); NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Application.Context, channelId) .SetContentTitle(title) .SetContentText(message); builder.SetCategory(Notification.CategoryAlarm); builder.SetPriority((int)NotificationPriority.Max); Intent mainIntent = AndroidApp.Application.Context.PackageManager.GetLaunchIntentForPackage(AndroidApp.Application.Context.PackageName); builder.SetContentIntent(AndroidApp.TaskStackBuilder .Create(AndroidApp.Application.Context) .AddNextIntent(mainIntent) .GetPendingIntent(messageId, PendingIntentFlags.OneShot) ); try { if (options.CustomActions != null) { foreach (var item in options.CustomActions) { Log.Debug("Alarm", "AlarmNotificationReceiver Action item : " + item.Name.ToString() + " notificationId : " + notificationId.ToString()); builder.AddAction(GetIconId(item.Icon), item.Name, GetButton(notificationId, item)); } } Log.Debug("Alarm", "AlarmNotificationReceiver ButtonsAdded : " + DateTime.Now.ToString()); int _smallIcon = string.IsNullOrEmpty(options?.SmallIcon) ? Essential.Platform.AppContext.ApplicationInfo.Icon : GetIconId(options.SmallIcon); int _largeIcon = string.IsNullOrEmpty(options?.LargeIcon) ? 0 : GetIconId(options.LargeIcon); Console.WriteLine("small icon : " + _smallIcon); Console.WriteLine("large icon : " + _largeIcon); if (_smallIcon != 0) { builder.SetSmallIcon(_smallIcon); } if (_largeIcon != 0) { builder.SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Application.Context.Resources, _largeIcon)); } if (options.EnableSound) { builder.SetSound(GetAlarmSound(options)); } if (options.EnableVibration) { builder.SetVibrate(new long[] { 1000, 1000, 1000 }); } CreateNotificationChannel(GetAlarmSound(options), options != null && options.EnableVibration); Notification notification = builder.Build(); manager.Notify(messageId, notification); var args = new LocalNotificationEventArgs() { Id = notificationId, Title = title, Message = message, }; NotificationReceived?.Invoke(null, args); } catch (Exception ex) { Log.Error("Alarm", "AlarmNotificationReceiver Notify : " + ex.Message); Log.Error("Alarm", "AlarmNotificationReceiver Notify : " + ex.StackTrace); var messages = new List <string>(); do { messages.Add(ex.Message); ex = ex.InnerException; }while (ex != null); var errmessage = string.Join(" - ", messages); Log.Error("Alarm", "AlarmNotificationReceiver Notify : " + errmessage); } return(notificationId); }