如何通过 Firebase 从 Google Cloud(GCP) 向 Android 应用程序发送通知

How do I send notifications from Google Cloud(GCP) via Firebase to an Android app

我知道如何将消息从 Firebase 云消息传递门户发送到 android 设备。但是我的服务器在 Google 云上运行,我在本地计算机上 gcloud app deploy 并且应用程序逻辑部署在 Google 云上。现在,我想根据 GCP 数据存储中存储为实体的数据向 Android 应用程序发送通知。

通知消息可以从 Firestore-Cloud Messaging 门户发送到 Android 设备,如果我可以在我的 GCP 逻辑中利用这个 Firestore Cloud Messaging API,那么我的问题就会得到解决。

我正在寻找任何示例或 POC。

您可以使用 Cloud Functions 添加此类自定义功能... 例如:https://android.jlelse.eu/serverless-notifications-with-cloud-functions-for-firebase-685d7c327cd4

还有 Cloud Datastore Callbacks, which can be used as event triggers. most relevant for Cloud Functions might be the Google Cloud Datastore Node.js Client - in order to connect to the Datastore. here's one of my examples,它是用 AppScript 编写的(类似于 Node.js),它也连接到 Cloud Datastore,服务帐户 JSON 从 Google 开车.

然而,在这种情况下,Datastore 需要随后触发 HTTP Trigger 或 Pub/Sub 触发器,并且该触发器背后的代码可以从 Datastore 获取更多数据或直接发送 Firebase 通知。

在 Cloud Function 中只有 Cloud Storage, while the Pub/Sub (publish/subscribe) 的触发器,触发器可以用于任何事情。 Datastore 需要发布任何事件 (add/edit/update/delete) - 而 Cloud Functions 脚本需要订阅这些事件。

使用 Firebase 作为后端可能更省力,因为数据更改 events/triggers 是开箱即用的支持,不涉及任何 HTTP 交互或 Pub/Sub 通信。