void SendLocalNotification(FcmDataNotification dataNotification) { // TODO do this in a platform specific service implementation var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); intent.PutExtra("message", "TODO: Set via PutExtra('message')"); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); // prepend groups with a # sign var groups = string.Join(' ', dataNotification.Groups.Select(g => $"#{g}")); var notificationBuilder = new NotificationCompat.Builder(this, AppSettings.Settings.Notifications.NotificationChannelName) .SetContentTitle($"Reminder: {groups}") .SetContentText(dataNotification.NeuronInformation) .SetStyle(new NotificationCompat.BigTextStyle()) //.SetContentInfo("ContentInfo") .SetSmallIcon(Resource.Drawable.icon) .SetAutoCancel(true) .SetShowWhen(false) .AddAction(new NotificationCompat.Action(0, "Snooze 1 hour", pendingIntent)) .AddAction(new NotificationCompat.Action(0, "Snooze 1 day", pendingIntent)) .AddAction(new NotificationCompat.Action(0, "Forget", pendingIntent)) .SetContentIntent(pendingIntent); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { notificationBuilder.SetChannelId(AppSettings.Settings.Notifications.NotificationChannelName); } var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(random.Next(), notificationBuilder.Build()); }
public override void OnMessageReceived(RemoteMessage message) { base.OnMessageReceived(message); // NOTE: test messages sent via the Azure portal will be received here var dataNotification = new FcmDataNotification(message.Data); SendLocalNotification(dataNotification); // send the incoming message directly to the MainPage SendMessageToMainPage("Notification directly to MainPage"); }