I followed this great article xamarinhelp.com/push-notifications/ and I have managed to get my device registered with Azure/FCM and I can receive a test notification in:
public class MyFirebaseMessagingService : FirebaseMessagingService
in OnMessageReceived and then SendNotification but I can't figure out how to process that message because although this routine is called, it just does nothing:
void SendNotification(string messageBody)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
var notificationBuilder = new Notification.Builder(this)
.SetContentTitle("FCM Message")
.SetSmallIcon(Resource.Drawable.ic_launcher)
.SetContentText(messageBody)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
var notificationManager = NotificationManager.FromContext(this);
notificationManager.Notify(0, notificationBuilder.Build());
}
I went through the second part of the article here https://xamarinhelp.com/push-notifications-lifecycle/ which mentions different handling of the message depending on whether the app is foregrounded or backgrounded etc. but no matter what state my app is in I always get the notification in the service/SendNotification as above ie. MainActivity is never re-created, MainActivity's OnNewIntent is never called (presumably because I see no clickable banner popped from the OS).
It is confusing because that article mentions GcmServiceBase but I don't use that (I only use FirebaseMessagingService) so I don't know if I am missing some code or if that article just references an old sdk.