应用程序没有收到我的 C2DM 消息?
这是我的 C2DMReceiver:
public class C2DMReceiver extends C2DMBaseReceiver {
public C2DMReceiver() {
// Email address currently not used by the C2DM Messaging framework
super("[email protected]");
}
@Override
public void onRegistered(Context context, String registrationId)
throws java.io.IOException {
// The registrationId should be send to your applicatioin server.
// We just log it to the LogCat view
// We will copy it from there
Log.e("C2DM", "Registration ID arrived: Fantastic!!!");
Log.e("C2DM", registrationId);
};
@Override
protected void onMessage(Context context, Intent intent) {
Log.e("C2DM", "Message: Fantastic!!!");
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
System.out.println(extras.get("payload"));
// Now do something smart based on the information
}
}
@Override
public void onError(Context context, String errorId) {
Log.e("C2DM", "Error!");
}
}
它应该做的是显示“消息:太棒了!!!”在 LogCat 中,但在任何地方都看不到它。我做错了什么?我的网络应用程序(用 PHP 编写)中有注册 ID,但没有运气。当我执行请求时,我得到了这个:
id=0:1311936686518981%48da2b9fb207fa19
使用指南:http://www.vogella。 de/articles/AndroidCloudToDeviceMessaging/article.html
Here is my C2DMReceiver:
public class C2DMReceiver extends C2DMBaseReceiver {
public C2DMReceiver() {
// Email address currently not used by the C2DM Messaging framework
super("[email protected]");
}
@Override
public void onRegistered(Context context, String registrationId)
throws java.io.IOException {
// The registrationId should be send to your applicatioin server.
// We just log it to the LogCat view
// We will copy it from there
Log.e("C2DM", "Registration ID arrived: Fantastic!!!");
Log.e("C2DM", registrationId);
};
@Override
protected void onMessage(Context context, Intent intent) {
Log.e("C2DM", "Message: Fantastic!!!");
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
System.out.println(extras.get("payload"));
// Now do something smart based on the information
}
}
@Override
public void onError(Context context, String errorId) {
Log.e("C2DM", "Error!");
}
}
What it should do is show "Message: Fantastic!!!" in the LogCat but it is no where to be seen. What am I doing wrong? I have the registration ID in my web application (written in PHP) but no luck. I get this back when i execute the request:
id=0:1311936686518981%48da2b9fb207fa19
Using guide: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用C2DM时需要处理很多事情。我认为你的代码看起来不错(尽管我还没有测试过)。你的
AndroidManifest.xml
怎么样?我花了将近两天的时间才意识到我的AndroidManifest.xml
包含一些错误,因此我无法使其工作。仔细阅读此文档,我建议您安装(当然,还要从源代码中学习)
ChromeToPhone
应用程序,以便您了解 C2DM 的关键。并且不要忘记 C2DM 仅适用于 Froyo (2.2) 及更高版本。
There's a lot of things you need to deal with when using C2DM. I think your code looks okay (even though I haven't test it yet). What about your
AndroidManifest.xml
? I've spent almost two days just to realize that myAndroidManifest.xml
contains some errors so I couldn't make it work.Read this documentation thoroughly and I suggest you to install (and learn from the source code, of course) the
ChromeToPhone
app so you know the key to C2DM here.And don't forget that C2DM only works for Froyo (2.2) and up.