且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用程序在后台时未调用 Firebase onMessageReceived

更新时间:2022-12-27 10:47:57

这是按预期工作的,只有当您的应用程序处于前台时,通知消息才会传递到您的 onMessageReceived 回调.如果您的应用处于后台或关闭状态,则通知中心会显示一条通知消息,并且该消息中的任何数据都会传递给用户点击通知.

This is working as intended, notification messages are delivered to your onMessageReceived callback only when your app is in the foreground. If your app is in the background or closed then a notification message is shown in the notification center, and any data from that message is passed to the intent that is launched as a result of the user tapping on the notification.

您可以指定 click_action 来指示当用户点击通知时应启动的意图.如果未指定 click_action,则使用主要活动.

You can specify a click_action to indicate the intent that should be launched when the notification is tapped by the user. The main activity is used if no click_action is specified.

启动意图时,您可以使用

When the intent is launched you can use the

getIntent().getExtras();

检索包含随通知消息一起发送的任何数据的 Set.

to retrieve a Set that would include any data sent along with the notification message.

有关通知消息的更多信息,请参阅文档.

For more on notification message see docs.