I have successfully implemented a client/server Android GCM application. My app server holds a database of device/registration_id pairs. Messages are sent to the devices via web accessible PHP pages. I am trying to write the error handling on the server side, specifically the case where the response contains a canonical_id. The developer docs are quite clear about what needs to be done and why such a response might be produced:
Canonical IDs
On the server side, as long as the application is behaving well,
everything should work normally. However, if a bug in the application
triggers multiple registrations for the same device, it can be hard to
reconcile state and you might end up with duplicate messages.GCM provides a facility called “canonical registration IDs” to easily
recover from these situations. A canonical registration ID is defined
to be the ID of the last registration requested by your application.
This is the ID that the server should use when sending messages to the
device.If later on you try to send a message using a different registration
ID, GCM will process the request as usual, but it will include the
canonical registration ID in the registration_id field of the
response. Make sure to replace the registration ID stored in your
server with this canonical ID, as eventually the ID you’re using will
stop working.
So within my Android client app I have a development only button which will register the device with GCMRegistrar.register() a second time without bothering to unregister it first. I had assumed that this would get me a registration_id different from the first time I registered it, and that sending a message to the device from the web (maybe using the old id) would give me a response with a canonical_id.
However the second registration returns exactly the same reg_id as the first time.
Thus sending a message via the PHP on my server won’t show a canonical_id in the response. I really need to test the situation where a canonical_id is returned, indicating that I need to update my database as my PHP skills are not the finest!
So any ideas as to how I could provoke such a response would be gratefully received
Update: I just tried uninstalling the app from the phone, then reinstalling it. I still get the same reg_id.
I answered that question – here.
You can try following the steps I used to get a canonical registration Id. It did involve uninstalling the App, but perhaps you didn’t do all the steps I describe there.