应用程序没有收到我的 C2DM 消息?

发布于 2024-11-27 05:26:28 字数 1509 浏览 2 评论 0原文

这是我的 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 技术交流群。

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

发布评论

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

评论(1

很快妥协 2024-12-04 05:26:28

使用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 my AndroidManifest.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.

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