首页 文章

Firebase Cloud可用于Android应用程序通知

提问于
浏览
0

我需要一些以下系统的提示:

  • 客户端应用:Android

  • 后端:Firebase Cloud功能

  • 数据库:实时数据库

其中一个场景如下:

  • 所有用户都在Android设备上 .

  • 用户通过OAuth2(Google帐户)登录 .

  • User1创建商品,商品在活动商品列表中为'waiting' .

  • 其他用户会收到更改已通知的活动优惠列表 .

  • User2请求优惠,优惠是'requested'

  • 其他用户会收到更改已通知的活动优惠列表 .

  • 用户1收到User2请求的通知

  • User1确认/拒绝User1的请求:

a)确认并且要约已“完成”并从有效要约列表中删除 .

b)拒绝并且优惠在活跃优惠列表中再次“等待” .

  • 其他用户会收到更改已通知的活动优惠列表 .

  • User2被通知User1的确认/拒绝

注意:系统是特定且有限的,因此活动商品列表将足够短,这就是为什么我正在考虑通知用户列表修改而不是单个商品修改,但我愿意接受建议 .

==========================================

我已经实现了以下内容:

  • User1创建了一个商品,商品正在“等待”:

  • android app调用createOffer(...)firebase Cloud 功能

  • createOffer(...)在实时数据库中向商品列表添加新商品 .

  • onWrite(...)实时数据库触发器在活动商品列表级别上触发

  • here I need the hint

  • User2请求优惠并且优惠是“已请求”:

  • android app调用requestOffer(...)firebase Cloud 功能

  • requestOffer(...)修改实时数据库中的商品 .

  • onWrite(...)实时数据库触发器在活动商品列表级别上触发

  • here I need the hint

  • here I need the hint

  • User1确认/拒绝User1的请求:

a)确认:

  • android app调用confirmnOfferRequest(...)firebase Cloud 功能

  • confirmOfferRequest(...)从活动商品列表中删除商品 .

  • onWrite(...)实时数据库触发器在活动商品列表级别上触发

b)否认:

  • android app调用denyOfferRequest(...)firebase Cloud 功能

  • denyOfferRequest(...)修改活动商品列表中的商品 . onWrite(...)实时数据库触发器在活动商品列表级别上触发 .

.

  • here I need the hint

  • here I need the hint

==================================

So I need hints about notifications to android application: steps 2, 4, 5, 7, 8

我想我应该使用FCM,但是:

  • 我发现的Android教程是关于已弃用的FirebaseInstanceId

  • 我不确定我的情况是什么:

  • 主题消息

  • 设备组

  • 上游消息

  • 我不知道如何通过onWrite(...)实时数据库触发器通知android应用程序 .

  • 仅应向登录用户通知有效的商品列表更改 . 如果用户被烧坏,则不应该通知,并且登录时应该获得实际状态(有效要约列表) .

=============

@James Poag ,谢谢你的提示 . 我会尽力提供反馈 .

我有一些问题:

当我说“通知”时,我并不是指设备的“状态栏”中的“真实”通知 . 至少当前的计划是在自身内部显示信息的应用程序 - 我称之为“通知” . 这似乎更简单 .

  • 是否有理由使用onCreate()而不是onWrite()?

目前我的计划是在创建/更新商品时执行相同的操作,所以我认为onWrite()可以解决这两种情况 . 或不 ?

  • 感谢交易提示:)

  • 我想在我的情况下我有“数据”消息,而不是“真实”通知 .


我必须阅读有关权限的内容 . 谢谢 .

我通过这种方式检查授权:

if (!context.auth) {
    return Promise.reject(Error('User is not authenticated.'));
}

1 回答

  • 1

    以下要点是您要使用Admin SDK发送消息 .

    您可以创建主题,让用户订阅主题,然后向主题发送消息(在上面的同一链接中介绍),或者如果有一小组用户,那么您可能只想向数据库中的每个人发送消息 .

    此外,不要依赖Android中的默认通知处理来获取FCM消息,请使用步骤2中的链接手动将通知发布到用户的托盘 .


    • User1创建了一个商品,商品正在“等待”:

    • android app调用createOffer(...)firebase Cloud 功能

    • createOffer(...)在实时数据库中向商品列表添加新商品 .

    • onWrite(...)实时数据库触发器在活动商品列表级别上触发 Consider using onCreate() instead of onWrite()

    • 使用admin sdk向您的应用用户发送通知 . 这将需要发送到组主题或迭代用户数据库并发送到用户的设备令牌 . 当您的用户使用设备登录时,grab their token from FirebaseMessaging并将其写入保存其配置文件的实时数据库 .

    • User2请求提供和要约是'要求':

    • android app调用requestOffer(...)firebase Cloud 功能

    • requestOffer(...)修改实时数据库中的商品 . Here you need to look into transactions to prevent multiple users from acquiring a lock on the Offer

    • onWrite(...)实时数据库触发器在活动商品列表级别上触发

    • Send a data only notification to the Topic group. Inside your Android app, process the data payload, open the NotificationManager and update the previous notification to 'requested'.

    • ***When the offer is created in the database, be sure to include the owner's device token. This way, when the offer state is changed to 'requested' you can use the admin sdk to fire off a notification to the owner. ***

    • User1确认/拒绝User1的请求:

    a)确认:

    • android app调用confirmnOfferRequest(...)firebase Cloud 功能

    • confirmOfferRequest(...)从活动商品列表中删除商品 .

    • onWrite(...)实时数据库触发器在活动商品列表级别上触发

    b)否认:

    • android app调用denyOfferRequest(...)firebase Cloud 功能

    • denyOfferRequest(...)修改活动商品列表中的商品 . onWrite(...)实时数据库触发器在活动商品列表级别上触发 .

    .

    • 与#4相同,但如果接受,则使用通知管理器完全取消通知

    • When User2 fires off step #3, they should send their device token as a part of the request. This way, when the request is accepted, your cloud functions will know who to notify.


    当用户登录设备时,将其令牌发送到Topic组 . 当他们注销时,从组中删除令牌(在实际注销之前) .

    由于所有内容都通过 Cloud 功能进行路由,因此您可以将数据库的权限设置为 .read : false, .write : false ,然后对于配置文件部分(如果需要),您可以添加特殊的 .write : auth !== null && auth.user === uid . 否则,Admin SDK具有从数据库读取/写入的特殊权限 .

    此外,当有人调用您的HTTPS功能以确保他们已登录到Firebase时,请查看authorization .

相关问题