实际上我试图通过Console中的Test On Device选项发送单个设备的通知。它显示已完成但未通过设备收到通知。然后我尝试了postman和pushtry.com,他们都给出了结果“Firebase推送通知已成功发送”,即使没有收到Android设备(Google Pixel Version 9)。请帮我解决这个问题。
您可能没有在MainActivity中使用Notification频道,您可以将其配置如下:
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);
}
然后从MainActivity的OnCreate方法中调用它
最小化您的应用程序(例如,转到仪表板或锁定手机)并发送FCM推送通知。如果您在这种情况下能够收到通知,则表示您已正确配置FCM。您共享的代码仅在您在后台申请时才有效。如果您希望在应用程序处于后台时收到通知。您必须实现继承FireBaseMessagingService调用并重写OnMessageRecived方法。