NishanthiKumari-8451 avatar image
0 Votes"
NishanthiKumari-8451 asked LeonLu-MSFT answered

Xamarin forms android Notification not Showing when app is running

I am using azure push notification with xamarin forms. messges are sending successfully, but when app is running its not visible in device.

this is my android code

    public override void OnMessageReceived(RemoteMessage message)
             var notification = message.GetNotification();
             var data = message.Data;
             string body = "";
             string title = "";
             if (data != null && data.ContainsKey("body") && data.ContainsKey("title"))
                 body = data["body"];
                 title = data["title"];
             else if (notification != null)
                 body = message.GetNotification().Body;
                 title = message.GetNotification().Title;
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered


Welcome to our Microsoft Q&A platform!

After you get the content from the RemoteMessage , you need to use code to push Notification.

public override void OnMessageReceived(RemoteMessage message)
        Log.Debug(Tag, "From: " + message.From);
        Log.Debug(Tag, "Notification Message Body: " + message.GetNotification().Body);

        var name = string.Empty;
        if (message.Data.Count > 0)
            Log.Debug(Tag, "Message data payload: " + message.Data);
            name = message.Data["name"];

        var clickAction = message.GetNotification().ClickAction;

        if (!string.IsNullOrEmpty(name))
            SendNotification(message.GetNotification().Body, name, clickAction);

void SendNotification(string messageBody, IDictionary<string, string> data)
    var intent = new Intent(this, typeof(MainActivity));
    foreach (var key in data.Keys)
        intent.PutExtra(key, data[key]);

    var pendingIntent = PendingIntent.GetActivity(this,

    var notificationBuilder = new  NotificationCompat.Builder(this, MainActivity.CHANNEL_ID)
                              .SetContentTitle("FCM Message")

    var notificationManager = NotificationManagerCompat.From(this);
    notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build());

For android 8.1 or later, before you push notification, you need to create CreateNotificationChannel as well.

void CreateNotificationChannel()
    if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        // Notification channels are new in API 26 (and not a part of the
        // support library). There is no need to create a notification
        // channel on older versions of Android.

    var channel = new NotificationChannel(CHANNEL_ID,
                                          "FCM Notifications",

                      Description = "Firebase Cloud Messages appear in this channel"

    var notificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);

Here is article about it.

Best Regards,

Leon Lu

If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.