简体   繁体   English

Android c2dm服务

[英]Android c2dm service

Trying to implement google C2DM service. 尝试实施google C2DM服务。

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. 还是Android知道如何处理此类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. 我将当前的Context传递给上述方法来创建注册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. 还是Android知道如何处理此类Intent。

Note that the intent is in the com.google.android.c2dm domain. 请注意,该意图位于com.google.android.c2dm域中。 The Android C2DM implementation on the device knows how to handle this intent and you will be starting its own service to process it. 设备上的Android C2DM实现知道如何处理此意图,因此您将启动自己的服务来对其进行处理。

No, you don't have to write a service. 不,您不必编写服务。 You need to send an intent to a Google's service. 您需要向Google服务发送意向书。 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"); Intent registrationIntent =新Intent(“ com.google.android.c2dm.intent.REGISTER”);

The line com.google.android.c2dm.intent.REGISTER identifies the Google's service. com.google.android.c2dm.intent.REGISTER行标识了Google的服务。

Now, you still have to write the broadcast receiver that'll receive the registration result (either an ID or error). 现在,您仍然必须编写将接收注册结果(ID或错误)的广播接收器。 And a receiver to receive the actual C2DM messages. 并有一个接收器来接收实际的C2DM消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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