Gcm device registration issue in android

2019-06-24 09:24发布

问题:

Currently i am working with push notification in android.its working fine.but my issues is am getting multiple notification instead of a single notification.then i check my device registration table and find a strange fact ,after each 30 minutes my device id is changing,so multiple device are resisted for same user_id and getting number of notification together .i don't know why this happen.i am using Samsung galaxy s2 for testing. please help me .

回答1:

I'm not sure why your registration id changes every 30 minutes. Perhaps if you post your registration code I'll be able to tell. Regardless to that issue, your server should be able to handle multiple registrations for the same device. When you send the registration id to your server, send with it another unique id created by your app or by your server, and that would allow you to identify when you get a new registration id for an existing device, in which case you'll replace the old registration id with the new one.

Another thing you should do at the server is handle the case where gcm server returns a canonical registration id, in which case you should replace the id you used for sending the message with the canonical one.