使用 Firebase 将通知从 android 台设备发送到另一台 android 台设备

Sending notifications from android device to another android device by using Firebase

我正在构建应用程序,我在其中实现了聊天以连接用户,问题是我需要在用户收到消息时通知他们

我试试这个 https://codelabs.developers.google.com/codelabs/firebase-android/#4 但它是从 Firebase 控制台向设备发送通知,这不是我需要的。我需要让用户向其他人发送通知

..

实际结果是我不知道如何在用户之间发送通知

在此视频中,一切都得到了解释:

https://www.youtube.com/watch?v=voIFz8aE9eE&list=PLGCjwl1RrtcQ3o2jmZtwu2wXEA4OIIq53&index=23

简历:

1) 创建一个名为 "Notification".

的节点

2)用你需要发送的内容创建HashMap。 例如:

 HashMap<String, Object> chatNotif = new HashMap<>();
        chatNotif.put("from", currentUserID);
        chatNotif.put("message", yourmessage);

        FirebaseDatabase.getInstance().getReference().child("Notifications").child(YOURFRIENDID).push().updateChildren(chatNotif);

3) 创建云函数

在视频中,这些人向您展示了如何编写一个云函数,每次您向此路径写入内容时都会触发该函数: 通知/$userID/$notificationkey

在此函数中,您将检索通知中的数据,并使用方法 sendToDevice

将您想要的内容简单地发送给用户 $userID