我已经阅读了许多有关Firebase推送通知行为的文档。当我的应用程序处于后台时,我能够在系统托盘上看到通知,但在应用程序处于前台时不会触发onMessageReceived
回拨。我可以在我的应用程序中看到该消息收到的日志。我试着用数据有效载荷进行调用,并且没有来自应用服务器的数据载荷我的应用服务器使用php脚本触发fcm apis。以下是我使用Firebase onMessageReceived未在前台应用程序调用
以下是我使用的服务,在我的Android应用
<service
android:name="service.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="service.MyFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
当你说你尝试过使用数据有效载荷时,你的意思是你在PHP代码中用JSON中的'data'替换了'notification'字段?即使你的应用程序处于前台,你的onMessageReceived方法没有被调用? – GeorgeLBA
我怀疑问题出在你的AndroidManifest.xml中。 尝试用“.service.MyFirebaseInstanceIdService”替换“service.MyFirebaseInstanceIdService”(注意开始处的点)。 请参阅https://developer.android.com/guide/topics/manifest/service-element.html中的“android:name”部分 –
@GeorgeLBA我试着一起发送通知和数据有效载荷。在使用和不使用数据有效负载的情况下,当应用处于前台时,不会调用onMessageReceived。我可以在FirebaseMessagingService中看到收到消息的日志 – LvN