I have been working on GCM for my Android app for a bit. I have noticed that almost every time I have a different GCM Registration ID for my device. Is it safe for me to keep a UNIQUE_KEY
constrain on GCM Registration ID? And delete all the IDs with the error NotRegistered
and update all the IDs which are canonical_ids
?
问题:
回答1:
a registration ID is tied to a particular Android application running on a particular device.
(from GCM Overview)
Two different devices would always have a different registration id. Even different apps on the same device have different registration ids.
Functionally it is safe to keep a UNIQUE_KEY constraint on the Registration ID, but since the Registration ID can be long (up to 4096 bytes, though in practice it's usually much shorter), some databases may prevent you from defining an index or constraint on such a large column. You might want to use a one way hash function that would map the Registration ID to a smaller value, store that value in a smaller column and have the constraint/index on that column.
When you get NotRegistered
error, you should indeed delete that registration ID from your DB (or at least mark it with a status that says it is inactive, and stop sending messages to it). But if the app will be re-installed on a device from which it was earlier uninstalled, the app may get the same registration ID when it registers again to GCM, so your server should allow registration IDs that at one point gave NotRegistered
to become active again.
You should update the old registration ID when you get canonical registration ID in the response from Google.
回答2:
It depends. In some cases, I have proved that Two or more devices can have identical Registration IDs. I have a push enabled phonegap app, that is made to run in several devices, all the same kind (brand, model, specs...). For saving time reasons, I decided to make a nandroid backup of one device and then copy that into the others. The result: many devices, the same Reg ID. Hope this helps.
回答3:
I am also confused regarding this due to following region, But i am not getting same registration Id as i Creates two demo also.
1) But one region, There is Particular sender id for Particular Application and according to that sender id there is a unique Registration id
Check for the Bold Line.As according to this Registration id always different for different application{Copy this line from http://developer.android.com/google/gcm/gcm.html}
Registration ID An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.
回答4:
The registration id is unique, what happens sometimes, is that your application changes. If you change the package name, or a whatever key used to be publish, debug or release key, then your registration id changes.