从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配置文件实现这一目标?
解决方法
关于这个话题,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.