在服务中处理 Google C2DM 意图?

发布于 2024-12-14 02:10:10 字数 180 浏览 0 评论 0原文

如果我正确设置 Android Manifest XML 文件,我可以在常规服务(而不是广播接收器)中处理 C2DM 意图(注册和接收)吗?

显然,需要为此设计应用程序,但我只是好奇是否有可能,或者是否有某些因素将 C2DM 意图限制为广播接收器,因为我在线阅读的每个示例都使用广播接收器,但似乎对我来说,人们也可以使用一项服务。

If I set up my Android Manifest XML file correctly, can I handle C2DM intents (REGISTRATION and RECEIVE) in a regular service, rather than a broadcast receiver?

Clearly, the application would need to be designed for this, but I'm just curious if it's possible or if something is limiting the C2DM intents to a broadcast receiver, as every example I've read online uses a broadcast receiver, but it seems to me one could use a service as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

度的依靠╰つ 2024-12-21 02:10:11

引自 GoogleAndroid 设备上的应用程序不需要运行来接收消息。只要应用程序设置了正确的广播接收器和权限,系统就会在消息到达时通过 Intent 广播唤醒应用程序。

所以,不会。接收消息的唯一方法是在广播接收器内。这没什么大不了的。通常,您会收到消息,然后致电服务部门。 Google 甚至为您提供了标准实施。 Google IO 会话Android + App Engine:开发人员的梦想组合使用向导(请参阅下面的安装)来生成代码。

例如,在 ChromeToPhone 代码:对于这 3 个类,您所要做的就是提供一个继承自 C2DMBaseReceiver 的类 C2DMReceiver 并设置清单。

更新
Google bloggt 关于客户端登录密钥过期。因此,我希望该插件得到更新以包含处理该问题的源代码。与上面的会话视频相比,有些事情发生了变化。首先你必须额外安装 android 向导(它不是 Google 插件的一部分):
Eclipse 向导安装
然后,如视频中所述,您必须使用此向导:new project
在生成的项目中,您可以找到 c2dm.jarc2dm-sources.jar。这些文件遍布互联网,但没有下载最新版本的主位置。所以你必须通过向导生成它们。源代码不包含版本注释,也不处理密钥过期问题。

Quote from Google: An application on an Android device doesn’t need to be running to receive messages. The system will wake up the application via Intent broadcast when the the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.

So, no. The only way to receive the messages is within a broadcast receiver. This is no big deal. Normally you receive the message and then you call a service. Google even provides you with an standard implementation. The Google IO session Android + App Engine: A Developer’s Dream Combination uses a wizard (see below for the installation) to generate the code.

Search for C2DMBaseReceiver, C2DMBroadcastReceiver and C2DMessaging for example in the ChromeToPhone code: all you have to do with these 3 classes is to provide a class C2DMReceiver which inherits from C2DMBaseReceiver and set up the manifest.

Update
Google bloggt about Client Login key expiration. Therefore I expected that the plugin gets updated to include source which deals with that. Compared to the session video above some things changed. First you have to install the android wizard extra (it is not part of the Google plugin):
Eclipse wizard installation
Then as described in the video you have to use this wizard:new project
In the generated project you can find c2dm.jar and c2dm-sources.jar. These files are spreaded all over the internet, but don't have a home location to download the latest version. So you have to generate them via the wizard. The source doesn't include a version comment and doesn't deal with the key expiration issues.

雨后咖啡店 2024-12-21 02:10:11

不,但您可以在广播接收器中接收广播,然后从中启动服务。

No, but you can receive the broadcast in a broadcast receiver and then start a service from that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文