0

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.

2 Answers 2

1

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.

1
1

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

2
  • But a Service can't be started with a 'broadcast' Intent. A better way would be to use a BroadcastReceiver which then calls startService(...) for whatever Service is to be used.
    – Squonk
    Nov 6, 2011 at 9:20
  • I wasn't too sure, but yea. I just changed my answer. Nov 6, 2011 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.