我想在後臺以及前臺處理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 –