user1537779
user1537779

Reputation: 2331

How to stack or group Registration IDs while using GCM?

I just started to use Google Cloud Messaging and read about User Notifications. According to this link, all the devices owned by a particular user will be notified at once.

In my case, a particular user is identified by his/her user_id and the database would look like this:

[user_id] [gcm_registration_id]

As per the demo, on the application side this registration_id is stored as persistent data.

What happens if the user uninstalls the app and the persistent data is gone?

  1. Will I get the same Registration ID for the same App on the same device once the user re-installs the app?

  2. Will Google invalidate these Registration IDs after some time?

Upvotes: 2

Views: 487

Answers (2)

Eran
Eran

Reputation: 394156

Actually the answer you accepted is not entirely correct.

I tested the case of un-installing and re-installing an app on a device, and in some cases you could get a different registration ID.

There are two cases :

    • You install an app, register to GCM and get a registration ID.
    • You un-install app
    • Your server sends a few messages to that registration ID, until you get a NotRegistered error from GCM (I believe you'll get that error only from the 2nd message you send).
    • You re-install the app
    • You receive a new registration ID when app register to GCM
    • If you now send a message with the old registration ID, it will still work, but you'll get the new registration ID in the response as canonical registration ID.
    • You install an app, register to GCM and get a registration ID.
    • You un-install app
    • The server doesn't send anything to that registration ID while the app is un-installed.
    • You re-install the app
    • You receive the same registration ID when app registers to GCM

Upvotes: 1

Pankaj Kumar
Pankaj Kumar

Reputation: 83048

will I get the same registration_id for the same app on the same device once the user reinstalls the app?

YES. Reg id chnages in two cases. Either your app will register OR Google refreshes the Registration ID. SO until any one cases executes your are fine with old reg id.

By any chance google invalidates these registration_ids after some time?

YES. Google refreshes the registration ID. GCM gives you the idea about handleing of updated registartion ID.


Handle updated id on client side

If the registration is successful, the GCM server broadcasts a com.google.android.c2dm.intent.REGISTRATION intent which gives the Android application a registration ID. The Android application should store this ID for later use (for instance, to check on onCreate() if it is already registered). Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.

Upvotes: 1

Related Questions