0

I have my app running on a Nexus 5 (Marshmallow) which has 2 active registration ids. Just want to know if that is normal by GCM behavior?


Here's how it's causing me trouble:

Android M has come up with Group permissions - which means the user chooses whether or not he wants the app to have access to his device identifiers (Android ID). Let's assume he denies it and I can't identify the device. The way my app functions is that a user can log in from multiple devices, all of which remain in sync. Because a user can be on mulitple devices, I must handle multiple registration IDs to send push messages (and I cant be sure of the number of devices the user is on, as they can deny providing the device identifiers). This means that I cant delete/update any registration ids on the server side, but only send every push message to all recorded IDs against a user, in the hope that all the devices on which that particular user is signed in will receive the messages.

Because I have a device which has two active registration IDs, I am getting 2 notifications for everything.


On the client end, we were noticing frequent changes in the Registration IDs, we have a class that keeps generating registration ids and updating the server.

  • The better idea to achieve this is registerimg user with some other details like user mobile number or email. Because after every new package the registeration id which is generated by phone itself will change. And moreover this id is of 160 characters so it occupies more space in database too. – Ankush Bist Dec 25 '15 at 13:06
  • Thanks, Ankush. However, notifications are more a device-level thing than a user-level thing. If we register a user with email address / phone number, how do we account for the possibility of users with multiple devices? Also, the question is more along the lines of whether or not it is possible for one device to have 2 **active** registration ids for the same app. – Yashash Agarwal Dec 26 '15 at 21:02
  • Sir, you are a developer use your brain. Think, if user can login using the same id in multiple devices use a single status for user to be login into only one device at a time. Like-store the user android device registration id too but this id will only be active after matching the registration of user. Means if the user is already exists in the database then we have to replace the registration id of the user in our database with the old registration id. This way user will be active in only one android device. – Ankush Bist Dec 28 '15 at 04:08

1 Answers1

0

Having multiple registration Ids can be a bug in the client app (which you have to deal with).

And the only way to ensure that there will only be one notification being sent per device is to implement canonical IDs on the server side. It is included in the webservice response as "canonical_ids".

Canonical IDs

If a bug in the client app triggers multiple registrations for the same device, it can be hard to reconcile state and the client app might end up with duplicate messages.

Implementing canonical IDs can help you more easily recover from these situations. A canonical registration ID is the registration token of the last registration requested by the client app . This is the ID that the server should use when sending messages to the device.

If you try to send a message using an old registration token, GCM will process the request as usual, but it will include the canonical ID in the registration_id field of the response. Make sure to replace the registration token stored in your server with this canonical ID, as eventually the old registration token will stop working.

Here is a related issue android GCM get original id of canonical id which tackles how canonical ids work in the actual code

Community
  • 1
  • 1
goblin
  • 1,513
  • 13
  • 13