0

When I send the Firebase notification to the app while the app is in the background, the notification appears in the system tray. When the user clicks on the notification, the app opens. In the app, the notification, intent extra provides the data sent with the notification.

if (getIntent().getExtras() != null) {
            for (String key : getIntent().getExtras().keySet()) {
                Object value = getIntent().getExtras().get(key);
                Log.d(TAG, "Key: " + key + " Value: " + value);
            }
        }

However, it does not include the notification title and body. onMessageReceived is also not called when background notification is received. Is there any way to get the title and message body of the background notification? One way I could do it to send them as key-value pairs in Additional options with the notification. It would be great if there is any better way to get the background notification title and body in the app.

user846316
  • 6,037
  • 6
  • 31
  • 40
  • 1
    you only need [data payload](https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages) and **not notification** payload – Rahul Khurana Mar 15 '19 at 08:23
  • I want the notification is displayed in the system tray but also want to store the title and body in the app as notification history after the user clicks the background notification. I can add title and body in data payload as well but I'm looking for some way to avoid that duplication. – user846316 Mar 15 '19 at 08:30
  • you can fetch the title and message in the data field and then generate the notification internally. – Rahul Khurana Mar 15 '19 at 09:04
  • Send a `data`-only message payload. Build the notification item yourself (see dup) and then do the other actions (store the payload details on local storage) as you want. – AL. Mar 15 '19 at 17:12

0 Answers0