Best practices implementing C2DM registration
Asked Answered
G

2

8

I'm developing an application that uses C2DM to receive push notifications. I've implemented the whole C2DM circuit (both client and server) and it's working fine.

Currently my applicacion has a button to bootstrap the C2DM registration, when receiving the registration id token from Google I call a webservice in my app server to associate the device with the registration id.

I'm going to implement authentication in my application and I have a few question related to the handling of the C2DM registration.

  1. The client application (ie the Android one) will have a login screen as the first screen so the user can enter the credentials. As soon as the credentials get validated I'm planning on calling the C2DM registration so the user gets associated with a registration id token. Is this ok? In later executions of the application I will probably store the credentials or some sort of token so the user doesn't need to enter the credentials again, Should I also fire the C2DM registration when the application launches?
  2. I'm aware that Google may eventually update the registration id. Is it a good practice to also update the registration id on a regular basis? If so, when should be appropiate? Does the registration id token expire?
  3. What happens in the rare case of a desynchronization of the registration id between the client and the server (eg a new registration id arrives at the client, in the middle of that a new event is fired on the server with the old registration id, then the registration id arrives at the server)? Will Google handle this cases? Should my app server handle this cases?
  4. What happens if the server is not reachable when a new registration id arrives from Google? Should I backoff and schedule an Alarm to try again?
  5. Can you think of any other pitfalls with this?
Gefell answered 3/5, 2011 at 2:52 Comment(0)
C
6

1) I would fire the C2DM registration as soon as possible. Nothing in particular, but since the request is asynchronous, firing it up early will help me get the reg ID sooner. However, no need to fire the registration each time the app starts. Once is sufficient.

2) Whenever Google decides to update the reg ID it will send it to the device and you need to do the same steps you followed when you receive the reg id for the first time i.e. convey it to the server.

3 & 4) You may want to go through this documentation. It stresses the fact that you need to make it sure that you send the registration ID to your server and keep on trying. I assume here that if the reg ID is refreshed, and your server still has the old ID, it will not be able to send messages to the device. It will receive a 200OK with an Error Code of InvalidRegistration which means a (missing or) bad registration id.

5) Cannot comment much - would say that it depends on the design of your application. But one thing worth noting is that C2DM is still in Beta so expect things to be different in the long run.

Cartogram answered 3/5, 2011 at 5:7 Comment(3)
Thanks for the answer, so basically you say to call once the registration procedure upon login and then only listen to changes by Google. Is that so?Gefell
yes. as I said, when Google refreshes the reg ID, your application should receive the REGISTRATION intent.Cartogram
Have you ever discovered a way of forcing Google to refresh the ID? I'd like to test and confirm my code is working correctly.Flabbergast
B
0
  1. Try to prompt the user with a choice of google accounts that are already on the phone. The http://code.google.com/p/chrometophone/source/checkout shows this. Look at SetupActivity.java for getGoogleAccounts(), etc.
Bernstein answered 16/9, 2011 at 2:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.