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

查看:239
本文介绍了从两个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项目集成在一起,并从它们接收推送通知?

解决方案

实际上,
$ b


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

FCM允许多方将消息发送到同一客户端应用程序。例如,假设客户端应用程序是一个包含多个贡献者的文章聚合器,并且他们每个应该能够在发布新文章时发送消息。此消息可能包含一个URL,以便客户端应用程序可以下载文章。 FCM让您不必将所有发送活动集中在一个位置,而是让每个发送者都能发送自己的信息。为了实现这一点,请确保每个发件人都会生成自己的发件人ID 。有关如何获取FCM发件人ID的信息,请参阅您的平台的客户端文档。当请求注册时,客户端应用程序多次获取令牌,每次在受众字段中使用不同的发件人ID。

最后,将注册令牌与相应的应用程序服务器(完成FCM注册客户端/服务器握手),他们将能够使用他们自己的认证密钥发送消息到客户端应用程序。



请注意限制100个发件人。

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


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


换句话说,您必须致电 getToken() 传递发件人ID并简单地FCM(例如, getToken(2xxxxx3344,FCM))作为参数。您必须确保您为每个发件人(项目)调用您需要的。



另外,请注意 getToken() docs:

lockquote

这是一个阻塞函数,所以不要在

一些额外的知识:


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

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?

解决方案

There is actually a part in the documentation about this topic:

Receiving messages from multiple senders

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.

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.

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.

Note that there is limit of 100 multiple senders.

I think the confusing but important part here is:

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

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.

Also, note from the getToken() docs:

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

Some additional good-to-knows:

  • It does not auto retry if it fails like the default one.
  • It returns an IOException when it fails.

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

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