Frank LaRosa
Frank LaRosa

Reputation: 3623

Android C2DM registration ID

I'm building an app that uses c2dm.

I think that I'm supposed to ask for a registration ID whenever my app's main "intent" starts up. I've been doing this, but it seems that each request results in a new string, so I end up piling up numerous registration IDs in my database for the same device. I presume that only one of them will work. However, I don't want to just delete the old ones because I want my user to be able to receive notifications on more than one device if they own more than one.

How should I handle this?

Upvotes: 3

Views: 2124

Answers (5)

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

Never to refresh ID untill your app is installed on your Device

I have implemented C2DM. If you have more than one registration ID for one device then only latest ID will work for sending notification.

When you register your device to google server then it generate a String(As you already know) corresponding to that device ID.But if you again register using same device then previous one is useless.

So i will suggest better to keep information that device is already registered or not.If registered then no need to re-register again.As you will get notification on the base of your old R_ID. simply send this R_ID to your server for notification purpose and save flag in your data base to keep track of registeration

Upvotes: 1

sarveshs
sarveshs

Reputation: 68

The registration ID for the device should be requested from the C2DM server only the first time the app is run after installation and then saved in the database( preferably along with the device ID so that it is unique).

The registration ID is valid as long as C2DM does not send the device a new registration ID, or the user uninstalls the app. I'm assuming you know how to handle the latter case.

Coming back to the first case. It is possible that during the lifetime of the application in the device the C2DM server may send the device a new registration ID[It will do so on its own and you do not have to request again for it]. Thus you should have a listener for the same, and you can update the registration ID of that device in your database.

Hope it helps.

Upvotes: 0

Kevin King
Kevin King

Reputation: 1559

If you register with the cloud, the returned registration ID will be valid until you receive the intent with the "unregistered" string extra (which will only occur if your application consciously unregisters with the service) OR Google sends another Registration intent with a new registration ID, in which case the system you have setup should work fine.

Your server will know if the registration ID has expired if it receives a 200 response with data "Error=NotRegistered". In this case, you would remove that entry from your DB.

http://code.google.com/android/c2dm/#server

Upvotes: 0

Olivier
Olivier

Reputation: 160

I am saving the registration_id with the device_id in the DB. That way I have only one entry for each device. Also the reg id is saved on the device as a shared preference so that I don't have to request a new one each time...

But I would like to know to if there is some way to find out if the reg id the user has on it's device is expired or not.

Any ideas? Is there an intent for it?

Upvotes: 0

Andrew
Andrew

Reputation: 16

Your only suppose to request a registration ID when you don't have one and send it to your server(the one that will send C2DM messages). It's strange that you keep getting a new id, in my own testing every time I register and unregister this same app on the same device I get the same id. I haven't done a lot of testing yet, but I would assume the id would change for every device and app combo.

Upvotes: 0

Related Questions