如何将消息发送到Android中的主题 [英] How to send message to the topic in Android
问题描述
如何通过Firebase发送主题消息?
我只使用Firebase Console,
以及Post方式HTTP请求,
,但我不明白如何在Android中执行。
如何在Android 谢谢。 您会看到这个示例中的方法与博客文章中的方法非常相似:都侦听数据库写入来触发发送FCM消息。示例中的一些更改与博客文章相比:示例用 b How to send a topic message via Firebase ? I only found the way to send by using Firebase Console ,
as well as some ways about Post HTTP requests ,
but I don't understand how to do it in Android. How can I write some codes in Android
to specify a topic which to target then send a message to the topic? Thanks. Sending a message to devices (so-called downstream messages) requires a HTTP call that specifies the server key. As its name implies, this key should only be used in environments you can trust. You cannot directly send a message from a device to other devices, including topics. This diagram from the Firebase Cloud Messaging documentation shows the flow: So if you want to send messages from an Android app, you will have to: One way to accomplish such a flow is described in our blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging. It uses the Firebase Database to communicate with a server-side script that then calls FCM to send the messages to topics. The server-side code in this post is a Node.js script, since it was the simplest approach available when I wrote it. But last week Firebase released Cloud Functions for Firebase. This allows you to run server-side code without managing your own infrastructure, which makes it a perfect fit for your use-case. In fact it is such a good fit that it's first in the documentation on use-cases for Cloud Functions for Firebase: You will see that the approach in this sample is very similar to the one in the blog post: both listen for database writes to trigger sending FCM messages. Some of the changes in the sample compared to the blog post: 这篇关于如何将消息发送到Android中的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
中编写一些代码要指定一个主题,然后发送一个消息到主题?
。 noreferrer>发送到设备令牌而不是主题。