Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to handle inbound push notification message from FCM

$
0
0

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.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>