如何使用Firebase云功能将设备发送到设备通知? [英] How to send device to device notifications using Firebase cloud functions?
问题描述
我知道这可能真的很容易,但是我找不到很好的开始参考.所以这是我的问题.我正在制作一个Android应用,需要在按钮单击时发送通知.
I know this might be really easy, but I can't find a good reference to start. So here is my questions. I am making an Android app that needs to send notification on button click.
通知可以发送到
- 安装了该应用程序的所有其他用户
- 安装了该应用程序的特定用户.
- all other users that installed the app
- specific users that installed the app.
发送通知本身的发送者一定不能获得通知警报.
The sender sending the notification itself must not get the notification alert.
我想通过使用 Firebase Cloud Functions 实现这一目标.但是我不知道如何开始.
I want to achieve this by using Firebase Cloud Functions. But I don't know like how to start.
如果有人向您展示Android Java代码片段和Firebase Cloud函数代码片段以实现相同功能,这将非常有帮助.
It'll be really helpful if someone showed snippets of Android Java code and Firebase Cloud functions code to achieve the same.
例如,假设有三个用户安装了我的示例应用程序 A , B 和 C .因此,如果A发送了通知警报,那么B和C都必须收到除A以外的警报.类似地,如果A要向特定用户B发送通知(例如,使用B的唯一用户ID 来说),则只有B必须收到通知,而不是C.
For example let's say there are three users A, B and C that installed my sample app. So if A sends a notification alert then B and C both must receive it except A. Similarly if A wants to send notification to particular user B (let's say by using B's unique user ID) then only B must receive the notification and not C.
推荐答案
要能够使用Firebase向某些用户发送通知,您可以编写一个JavaScript函数,该函数将侦听某些触发数据库的事件.
To be able to send notifications to certain group of users with Firebase, you can write a JavaScript function that will listen for some events that triggers your database.
触发此事件后,您可以执行操作,在这种情况下,您将需要编写JavaScript(或TypeScript)函数,该函数可以找到设备令牌以发送通知和通知有效负载.该示例非常清楚如何进行操作,并且是Firebase函数存储库中的函数示例集合的一部分.
When this events are triggered you can perform an operation, in this case, you will need to write a JavaScript (or TypeScript) function that can find the device token to send the notification and a notification payload. This example is very clear on how to do it, and it's part of a collection of function samples on the Firebase functions repo.
https://github.com/firebase/functions -samples/tree/Node-8/fcm-notifications
这篇关于如何使用Firebase云功能将设备发送到设备通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!