简体   繁体   English

Xamarin Android 中的 Android 设备未收到通知

[英]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.然后我尝试了 postman 和 pushtry.com,他们都给出了结果“Firebase 推送通知发送成功”,即使没有收到 android 设备(谷歌像素版本 9)。 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:您的 MainActivity 中可能没有通知通道,您可以将其配置如下:

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然后从 MainActivity 的 OnCreate 方法中调用

Minimize your application(for example go to dashboard or lock the phone) and send the FCM push notification.最小化您的应用程序(例如转到仪表板或锁定手机)并发送 FCM 推送通知。 If you able receive the notification in this case, that mean you FCM is configured properly.如果您在这种情况下能够收到通知,则表示您的 FCM 配置正确。 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.您必须实现继承 FireBaseMessagingService 调用并覆盖 OnMessageRecived 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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