GCM testing, how to provoke a GCM server response using canonical_id?

I have successfully implemented the Android GCM application for client / server. My application server contains a database of device pairs / registration _id. Messages are sent to devices via PHP web pages. I am trying to write server-side error handling, in particular the case where the response contains canonical_id. The developer documents clearly indicate what needs to be done and why such an answer can be obtained:

Canonical identifiers

On the server side, as long as the application behaves well, everything should work fine. However, if an error in the application triggers multiple registrations for the same device, it can be difficult and you may get 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 in your server with this canonical identifier, because in the end the identifier you use will stop working.

So, in my Android client application, I have a development-only button that will register the device using GCMRegistrar.register () a second time, without worrying about unregistering first. I suggested that this would result in I registering a registration other than the first one when I registered it, and that sending a message to the device from the Internet (possibly using the old identifier) ​​will give me an answer using canonical_id.

However, the second registration returns exactly the same reg_id as the first time.

Thus, sending a message via PHP on my server will not show canonical_id in the response. I really need to check the situation when canonical_id returns, indicating that I need to update my database, since my PHP skills are not the best!

So any ideas on how I could provoke such an answer would be gratefully accepted

Update: I just tried to uninstall the application from the phone and then reinstalled it. I am still getting the same reg_id.

+4
source share
2 answers

I answered this question here . You can try to follow the steps that I used to get the canonical registration identifier. This is due to uninstalling the application, but you may not have completed all the steps I described.

+3
source

I understand that the canonical identifier that needs updating will only come from the server. This will only happen if the GCM servers discover that they have two identifiers for the same device.

This can only happen if there is any race condition or other error that is difficult to reproduce. I understand your desire to test this scenario, but I use GCM because it came out of beta and never saw the canonical replacement of the identifier pass.

0
source

Source: https://habr.com/ru/post/1443212/


All Articles