接收来自两个 Firebase 项目的一个 Android 应用的推送通知 [英] Receive push notifications on one android app from two Firebase projects

查看:25
本文介绍了接收来自两个 Firebase 项目的一个 Android 应用的推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Android 应用,我希望它能够接收来自两个不同 Firebase 项目的推送通知.

我阅读了博客在 Android 应用程序中使用多个 Firebase 项目"https://firebase.googleblog.com/2016/12/working-with-multiple-firebase-projects-in-an-android-app.html 其中谈到从两个不同的 Firebase 项目访问数据库".
但是,没有关于从多个 Firebase 项目接收通知的信息.

那么,如何将我的应用与多个 Firebase 项目集成并接收来自它们的推送通知?

I have an Android app, and I want it be able to receive push notifications from two different Firebase projects.

I read the blog "Working with multiple Firebase projects in an Android app" https://firebase.googleblog.com/2016/12/working-with-multiple-firebase-projects-in-an-android-app.html which talks about "Accessing the Databases from two different Firebase projects".
However, there is no info about receiving notifications from multiple Firebase projects.

So, how to integrate my app with multiple Firebase projects and receive push notifications from them?

推荐答案

文档 关于这个主题:

接收来自多个发件人的邮件

Receiving messages from multiple senders

FCM 允许多方向同一个客户端应用发送消息.例如,假设客户端应用程序是具有多个贡献者的文章聚合器,并且每个贡献者都应该能够在发布新文章时发送消息.此消息可能包含一个 URL,以便客户端应用程序可以下载文章.FCM 无需将所有发送活动集中在一个位置,而是让您能够让这些贡献者中的每一个都发送自己的消息.

FCM allows multiple parties to send messages to the same client app. For example, suppose the client app is an article aggregator with multiple contributors, and each of them should be able to send a message when they publish a new article. This message might contain a URL so that the client app can download the article. Instead of having to centralize all sending activity in one location, FCM gives you the ability to let each of these contributors send its own messages.

为了实现这一点,请确保每个发件人都生成自己的发件人 ID.有关如何获取 FCM 发件人 ID 的信息,请参阅您平台的客户端文档.请求注册时,客户端应用多次获取令牌,每次在受众字段中使用不同的发件人 ID.

To make this possible, make sure each sender generates its own sender ID. See the client documentation for your platform for information on on how to obtain the FCM sender ID. When requesting registration, the client app fetches the token multiple times, each time with a different sender ID in audience field.

最后,与相应的应用服务器共享注册令牌(以完成 FCM 注册客户端/服务器握手),他们将能够使用自己的身份验证密钥向客户端应用发送消息.

Finally, share the registration token with the corresponding app servers (to complete the FCM registration client/server handshake), and they'll be able to send messages to the client app using their own authentication keys.

请注意,有 100 个多个发件人的限制.

Note that there is limit of 100 multiple senders.

我认为这里令人困惑但重要的部分是:

I think the confusing but important part here is:

请求注册时,客户端应用多次获取令牌,每次在受众字段中使用不同的发件人 ID.

When requesting registration, the client app fetches the token multiple times, each time with a different sender ID in audience field.

换句话说,您必须调用 getToken() 传递发件人 ID 和简单的 FCM" (例如 getToken("2xxxxx3344", "FCM")) 作为参数.您必须确保为您需要的每个发件人(项目)调用此方法.

In other terms, you'll have to call getToken() passing the Sender ID and simply "FCM" (e.g. getToken("2xxxxx3344", "FCM")) as the parameters. You'll have to make sure that you call this for each sender (project) that you need.

另外,请注意 getToken() 文档:

Also, note from the getToken() docs:

这是一个阻塞函数,所以不要在主线程上调用它.

This is a blocking function so do not call it on the main thread.

一些额外的注意事项:

  • 如果它像默认的那样失败,它不会自动重试.
  • 它在失败时返回一个 IOException.

这篇关于接收来自两个 Firebase 项目的一个 Android 应用的推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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