Two Push Notification services in android

给你一囗甜甜゛ 提交于 2019-12-23 12:47:05

问题


I have integrated Parse SDK with my project already and implemented Parse Push Notification and its working perfectly. But the Problem is: When I integrate another Push Service in my project, the parse Push Stops working?

Note:

1.Parse uses its own push service.

2.The new Push I tried to use use GCM push service.

Is there any clash between them or is there any way we can manage both?


回答1:


When you use two Gcm clients with Gcm broadcast receiver in your own project - the last broadcast receiver registered will get the msgs coming from the Gcm servers. in other words - there will always be only one broadcast receiver that will get these msgs . In your case - the second service you added is receiving the Gcm msgs because it was registered last, probably handling it's own msgs and discarding the others.

Had a similar similar problem in my app where I used a lib that used Gcm msgs and my app was using Gcm as well. after adding the services and broadcast receivers in the app's manifest - the lib stopped receiving Gcm msgs.

The solution is not elegant - In the onReceive function of the broadcast receiver - I distinguished between Gcm msgs targeting my app and those targeting the lib in my broadcast receiver , handled the ones for my app as they should and for the ones targeting the lib - I start a new intent with the extras data , which triggered the lib's broadcast receiver. I could take this approach because I control the code for both the app and lib.

Hope this helps.



来源:https://stackoverflow.com/questions/34610972/two-push-notification-services-in-android

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