Firebase Cloud Messaging not sending data payload

Viewed 1359

From the Firebase Cloud Messaging documentation at Defining message payload:

You can specify one or both message types by creating an object with the data and / or notification keys.

The documentation gives the example of a Combined Message:

var payload = {
  notification: {
    title: "$GOOG up 1.43% on the day",
    body: "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day."
  },
  data: {
    stock: "GOOG",
    open: 829.62,
    close: "635.67"
  }
};

Also from the documentation at Handle notification messages in a backgrounded app:

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

I'm sending a notification with this payload:

const payload = {
    notification: {
        title: '...',
        body: '...',
    },
    data: {
        test: "test"
    },
};
admin.messaging().sendToDevice(tokens, payload).then(...)

But extras is always null:

Intent intent = getIntent();
if (intent != null) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        // do something
    }
}

What am I doing wrong?

1 Answers
Related