GCM notification duplication issue. Received same message many times

你离开我真会死。 提交于 2019-12-11 10:38:02

问题


I have noticed one issue in dealing with GCM. If you un-install the app and install it again the GCM registration id is changed for that device. And previous registration id is still working. So in my database there are multiple registration ids which are referring to one device. So sending only one notification received multiple times on the device.

Please help me on this.


回答1:


You can solve this issue, with the use of canonical_id which is part of the response of GCM when called for sending push messages. Canonical Id can be used to detect duplicate register ids and you can use to prevent the problem.

Also you can read more about it in the following links

1- How to get Canonical Id from GCM ?

2- How to resolve the GCM duplicate messages problem ?




回答2:


You can delete previous GCM id stored in you database while inserting new GCM id for the same user or device if you can track the same user somehow for example by loginid.




回答3:


As mentioned in the guideline of GCM

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.

You can replace the old GCM in your database instead of keeping duplicate copies as multiple Registration Ids are the reason for multiple push notifications.



来源:https://stackoverflow.com/questions/35519368/gcm-notification-duplication-issue-received-same-message-many-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!