简体   繁体   中英

Android c2dm service

Trying to implement google C2DM service.

registrationIntent.putExtra("app", PendingIntent.getBroadcast(context,0,new Intent(), 0));
registrationIntent.putExtra("sender","example@gmail.com");
context.startService(registrationIntent);

Almost every tutorial features this line of code. Is this a service that I must code? or does Android know how to handle this type of Intent. I am calling this method from a helper class with the default constructor. I pass the current Context to the this above method to create the registration Intent. Anyone have some insight on how this works or where my program will go?

You left out the most interesting piece of code

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");

Is this a service that I must code? or does Android know how to handle this type of Intent.

Note that the intent is in the com.google.android.c2dm domain. The Android C2DM implementation on the device knows how to handle this intent and you will be starting its own service to process it.

No, you don't have to write a service. You need to send an intent to a Google's service. You've omitted the first line, where the intent is created, and that contains the service name. It's something like this typically:

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");

The line com.google.android.c2dm.intent.REGISTER identifies the Google's service.

Now, you still have to write the broadcast receiver that'll receive the registration result (either an ID or error). And a receiver to receive the actual C2DM messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM