Skip to content

Instantly share code, notes, and snippets.

@sjones94549
sjones94549 / Multiple_GCM_Senders.md
Last active November 13, 2017 01:18
How to handle multiple GCM senders in the same app

Multiple GCM Senders in the Same App

Google does support multiple GCM senders (Layer, etc.) for a single app, but you have to account for it. If not, one or more GCM sender will fail to send GCM intents, and GCM intents that do come in may randomly fail to reach GCM receivers in your manifest.

GCM Registration

GCM registration happens in two phases. First, the device supplies a Sender ID to Google, and Google gives the device back a Registration ID. The Registration ID is what the device sends to Layer so we can send GCM to that device. The trick is, each app can only have one current Registration ID assigned by Google at a time; previously assigned Registration IDs will no longer work. And, the Registration ID is based on the Sender ID supplied at registration time. So, if multiple senders (e.g. Layer and another service) register for GCM, one will register last and invalidate the other.

Option 1: Handling GCM Registration Yourself

The first method is documented: