Notification click event in xamarin forms [closed]

2019-06-11 23:15发布

问题:

I want to open an xaml page when user clicks on the Notification. I've searched but cant find a decent sample for this situation. By the way I'm using FCM with old GCM integration.How can I achieve this in android ?

回答1:

I want to open an xaml page when user clicks on the notification .

When you receive a Notification from FCM, you could add a PendingIntent in Notification to implement this function, this will allow the user to open the app. Code like this :

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)
            .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
            .SetContentTitle("FCM Message")
            .SetContentText(messageBody)
            .SetAutoCancel(true)
            .SetContentIntent(pendingIntent);

        var notificationManager = NotificationManager.FromContext(this);
        notificationManager.Notify(0, notificationBuilder.Build());
    }

For more information, you could read the document and here is the complete code.