【问题标题】:Enabling the notification feature for my firebase app为我的 firebase 应用启用通知功能
【发布时间】:2018-09-24 13:15:04
【问题描述】:

我使用 firebase 制作了一个应用程序。它基本上是一个聊天应用程序,您可以在其中发送和接收文本和图像。我想在其中添加一个功能,每当用户发送消息时,另一个用户应该收到通知。当我尝试通过 firebase 控制台发送通知时,它正在工作,但是当用户通过应用程序发送消息时,它不会向其他用户显示任何通知。那么,谁能告诉我这个功能是如何实现的?另外,提供一些示例代码来看看事情是如何工作的

【问题讨论】:

  • 你检查答案了吗?

标签: firebase firebase-realtime-database firebase-authentication firebase-cloud-messaging android-notifications


【解决方案1】:

您需要为此使用云功能:

https://firebase.google.com/docs/functions

Cloud Functions for Firebase 可让您自动运行后端代码以响应由 Firebase 功能和 HTTPS 请求触发的事件

首先,您可以将用户注册到topic

FirebaseMessaging.getInstance().subscribeToTopic("news");

https://firebase.google.com/docs/cloud-messaging/android/topic-messaging

然后当消息发送到数据库时,您可以在云函数中使用onWrite(),这是一个数据库触发器,可以发送通知。

https://firebase.google.com/docs/functions/database-events

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2019-12-18
    • 2017-09-28
    • 2020-09-24
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    相关资源
    最近更新 更多