如何通过Firebase将来自Google Cloud(GCP)的通知发送到Android应用 [英] How do I send notifications from Google Cloud(GCP) via Firebase to an Android app

本文介绍了如何通过Firebase将来自Google Cloud(GCP)的通知发送到Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know how to send messages from Firebase cloud messaging portal to an android device. But my server runs on Google Cloud, I do gcloud app deploy from my local machine and the app logic gets deployed on Google Cloud. Now, I want to send notifications, based on the data stored as Entities in GCP Datastore, to an Android App.

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

Notification messages can be sent from Firestore-Cloud Messaging portal to an Android device, if I could harness this Firestore Cloud Messaging API in my GCP logic, then my problem will be solved.

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

I'm trying to look for any examples or POC's.

推荐答案

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

you can use Cloud Functions to add such custom functionality... for example: https://android.jlelse.eu/serverless-notifications-with-cloud-functions-for-firebase-685d7c327cd4

,并且有 Cloud Datastore回调,它可以用作事件触发器.与Cloud Functions最相关的可能是 Google Cloud Datastore Node.js客户端-为了连接到数据存储.这是我的一个例子,它是用AppScript(类似于Node.js),也使用从Google云端硬盘加载的服务帐户JSON连接到Cloud Datastore.

and there are 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, it is written in AppScript (similar to Node.js), which also connects to a Cloud Datastore, with the service account JSON loaded from Google Drive.

但是,在这种情况下,数据存储区将需要随后触发 HTTP触发器或发布/订阅"触发器以及该触发器后面的代码可以从数据存储区获取更多数据或直接发送Firebase通知.

however, in this case the Datastore would need to subsequently trigger an HTTP Trigger or Pub/Sub Trigger and the code behind that trigger could get more data from the Datastore or directly send the Firebase notification.

在Cloud Function中,只有 Cloud Storage 的触发器, 发布/订阅(发布/订阅)触发器可以用于任何事物.数据存储区将需要发布任何事件(添加/编辑/更新/删除),而Cloud Functions脚本将需要订阅这些事件.

in Cloud Function there are just triggers for Cloud Storage, while the Pub/Sub (publish/subscribe) triggers can be used for just anything. The Datastore would need to publish whatever event (add/edit/update/delete) - while a Cloud Functions script would need to subscribe these events.

使用Firebase作为后端可能会花费更少的精力,因为开箱即用地支持数据更改事件/触发器,而无需任何HTTP交互或发布/订阅通信.

using Firebase as backend might be less effort, because data-change events/triggers are being supported out-of-the-box, without any HTTP interaction or Pub/Sub communication involved.

这篇关于如何通过Firebase将来自Google Cloud(GCP)的通知发送到Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆