我想在后台以及前台处理Firebase通知消息。我将发送一条消息,其中包含来自开发人员的YouTube链接,当用户点击通知栏时,必须指示用户打开链接。有谁知道它是如何完成的?如何处理背景以及前景的Firebase通知?
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user taps on the notification they are returned to the app. Messages containing both notification
// and data payloads are treated as notification messages. The Firebase console always sends notification
// [END_EXCLUDE]
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be:
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
接下来做什么来达到我的目标?在此先感谢:)
发布的代码只是示例中的代码。所以我假设你已经经历过他们。有什么困惑吗?你是否也阅读过文档?现在,这就像一个*给我代码*问题。 –
试试我的解决方案?
我已经试过了。
它的工作
https://stackoverflow.com/questions/48897883/how-to-handle-notifications-with-fcm-when-app-is-in-e-fore-foreground-or-backgro/48899186#48899186 –