使用GcmListenerService的多个GCM侦听器 [英] Multiple GCM listeners using GcmListenerService

查看:161
本文介绍了使用GcmListenerService的多个GCM侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google建议使用GcmListenerService来代替GcmBroadcastReceiver。

Google is recommending to use GcmListenerService in place of GcmBroadcastReceiver.

制作一个使用GCM的库项目(com.android.library插件)。当Application项目(com.android.application插件)不使用GCM时,它工作的很好。

Am making a Library project(com.android.library plugin) which is using GCM. It works well when Application project(com.android.application plugin) is NOT using GCM for it's own.

当Application项目使用GCM作为它自己的库项目接收器没有被调用!

When Application project is using GCM for it's own, Library project receiver is not getting called!

库模块定义了GCM权限和接收器&服务条目在它的清单中。 App模块在它自己的清单中定义了它的服务条目。

Library module has defined GCM permissions and receiver & service entries in it's manifest. App module has defined it's service entry in it's own manifest.

使用GcmBroadcastReceiver,这可能是可能的,因为它是一个广播。在这里也看到很多问题。不希望因为弃用而使用GcmBroadcastReceiver。

With GcmBroadcastReceiver this could've been possible, as it is a broadcast. Have seen many questions here for the same. Don't want to use GcmBroadcastReceiver because of deprecation.

是否有任何方法可以使这项工作成为可能?

Is there any way to make this work?

编辑:将调用哪个服务取决于合并清单xml中定义的顺序。如果我颠倒了订单,另一个服务正在被调用!有什么办法可以调用这两个服务?

Which Service will get invoked is depends on order in which it's defined in merged manifest xml. If I reverse the order, the other Service is getting invoked! Is there any way to call both Services?

推荐答案

最好的解决方案是只有一个GcmListenerService实现,消息。

The best solution would be to just have one GcmListenerService implementation, and have this handle messages for both.

如果你真的想要两个实现,通过增加优先级来实现一个主实现( see here )。然后,您可以通过创建数据意图,显式设置组件,然后启动其他服务来调用第二个服务。

If you really want to have two implementations, make one the main implementation by increasing it's priority (see here). Then you can have that service invoke the second one by creating an intent with the data, explicitly setting the component, then starting the other service.

这篇关于使用GcmListenerService的多个GCM侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆