Gcm canonical id should be updated or not

I am working on an Android project that uses gcm. I found out that if we remove the appfrom device and reinstall most of the time when the device receives a new registration ID. Then, if we do not delete the old application server and do not update, messages will be sent both for identifiers and will display a canonical identifier in response. My question is, at what point will the message be sent successfully to this device or not?

+6
android push-notification google-cloud-messaging
source share
2 answers

When you receive the canonical registration identifier in the response from Google, the message was received by the GCM server and the GCM server will try to deliver it to the device. Whether it will actually be sent to the device depends on whether the device is accessible (i.e. connected to the Internet). Therefore, if your server sends a GCM message to both the old identifier and the new ID, the device will probably receive two messages.

Canonical identifiers

On the server side, as long as the application behaves well, everything should work fine. However, if an application error triggers multiple registrations for the same device, it can be difficult to reconcile the state and , you may receive duplicate messages .

GCM provides a facility called "canonical registration identifiers" easily from these situations. A canonical registration identifier is defined to be the identifier of the last registration requested by your application. This is the identifier that the server should use when sending messages to the device.

If you later try to send a message using a different registration ID, GCM will process the request as usual, but it will include the canonical registration identifier in the registration_id response field . Be sure to replace the registration identifier stored on your server with this canonical identifier, because in the end the identifier you use will stop working.

( Source )

You can solve this problem by assigning a unique identifier for each instance of your application. If you store this identifier in the external storage of the device, it will not be deleted when the application is deleted. Then you can restore it when the application is installed again. If you send this identifier to your server along with the registration identifier, you can check if your server has an old registration identifier for this identifier and removes it.

+5
source share

@Eran We have two options: delete the old registration identifiers or update with the key and the position of the canonical identifier. I prefer to update ... You can see my working code, which I answered here. Steps for updating canonical identifiers

0
source share

All Articles