android – 如何在google-services.json中放置多个project_number / sender id

前端之家收集整理的这篇文章主要介绍了android – 如何在google-services.json中放置多个project_number / sender id前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我希望能够在我的 Android应用程序中添加多个发件人ID.

https://developers.google.com/cloud-messaging/concept-options

GCM allows multiple parties to send messages to the same client app. For example,suppose the client app is an articles 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,GCM gives you the ability to let each of these contributors send its own messages.

如何使用google-services.json配置文件实现这一目标?

解决方法

更新:要参考官方和推荐的方式,而不是采用hacky和非官方方法来防止/避免未知问题.从我的回答 here.

关于这个话题,documentation实际上有一部分:

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,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 07002. 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.

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

When requesting registration,each time with a different sender ID in audience field.

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

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

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

一些额外的好消息:

>如果它像默认值一样失败,它不会自动重试.>失败时返回IOException.

猜你在找的Android相关文章