Android 当应用程序处于后台时,在onMessageReceived中未接收Firebase通知

Android 当应用程序处于后台时,在onMessageReceived中未接收Firebase通知,android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,我可以使用FCM在我的应用程序中发送通知,所有功能都很好,但当我的应用程序位于后台时,通知将由android系统通知托盘处理 我想处理来自我自己的通知我正在发送此有效负载以发送通知 $fields = array( 'notification' => $notification, 'to' => '/topics/updates' ); 当我的应用程序在放弃时,这将调用我的onMessageReceived,但当我的应用程序在后台时

我可以使用
FCM
在我的应用程序中发送通知,所有功能都很好,但当我的应用程序位于后台时,通知将由android系统通知托盘处理

我想处理来自我自己的通知我正在发送此有效负载以发送通知

$fields = array(
        'notification' => $notification,
        'to'  => '/topics/updates'
        );
当我的应用程序在
放弃时,这将调用我的
onMessageReceived
,但当我的应用程序在后台时,这将不会调用我的
onMessageReceived
请求由系统本身处理

当我的应用程序处于
后台时,我想调用我的
onMessageReceived

我还尝试删除
通知键
,只发送
数据键
,如下所示

$fields = array(
        'data' => $notification,
        'to'  => '/topics/updates'
        );
但是当我从上面发送请求时,
onMessageReceived
字段在
forground和background

我正在我的
小米红米note 4(oreo)
红米4x(android 10)
android emulator(marshmello)

我遵循这个ans来解决我的问题,但不是为我工作

我的FCM版本是
17.3.4

我的android studio版本是
3.5.3

如果没有收到数据消息,那么负载可能是错误的。下面是我的有效负载示例(.js,但结构应该基本相同):


很抱歉,当我们只发布数据密钥而不是通知密钥时,发布此愚蠢的问题FCM在后台工作

我的错误是我用这个包装我的通知生成器

if (remoteMessage.getNotification() != null) {
 // other code
}

我试过这个有效载荷在背景和背景下不工作
if (remoteMessage.getNotification() != null) {
 // other code
}