简体   繁体   中英

Notification Not Received on Android Device in Xamarin Android

Actually I tried to send notification for single device through Test On Device option in Console. It shows completed but notification not received by device. And then I tried postman and pushtry.com, both of them gave result "Firebase Push Notification Sent Successfully", even though the android device(Google Pixel Version 9) not received. Please help me to resolve this problem.

You are probably not having a Notification channel in your MainActivity you can configure it something like below:

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.
        return;
    }

    var channel = new NotificationChannel(CHANNEL_ID, "FCM Notifications", NotificationImportance.Default)
                  {
                      Description = "Firebase Cloud Messages appear in this channel"
                  };

    var notificationManager = (NotificationManager) GetSystemService(NotificationService);
    notificationManager.CreateNotificationChannel(channel);
}

And then call it from MainActivity's OnCreate Method

Minimize your application(for example go to dashboard or lock the phone) and send the FCM push notification. If you able receive the notification in this case, that mean you FCM is configured properly. The code you share will only work if you app in in background. IF you wish to receive the notification when app is in background. You have to implement inherit FireBaseMessagingService call and override OnMessageRecived method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM