Firebase Cloud Messaging: how to send data message

2019-06-02 07:45发布

This question already has an answer here:

I would like to send data messages to all users.

Is it possible to do it programmatically, without using the Firebase Notifications Console?

The problem with the Console is that the "message text" field at the beginning of the form is compulsory. So, even if I add the custom data key/values, there will also be the standard notification component.

As stated here, when the message includes both notification and data, in case the app is in the background, a standard notification message will be notified to the system tray.

I would like instead to deliver only a notification based on the custom data (trigged by OnMessageReceived).

How can I achieve that? Programmatically, I can correctly send data messages to specific users, but I cannot find a way to send data messages to ALL users.

1条回答
Melony?
2楼-- · 2019-06-02 08:04

Use topic messaging. You can define the name of a topic that all installations of your app will subscribe to, then send the message to that topic.

You can use the Firebase Admin SDK from your server to send that message. Or you can use the FCM HTTP API to send that message.

查看更多
登录 后发表回答