是否必须在注册该代码的同一应用程序中编写c2dm代码?

问题描述

| 我是android上的新开发人员,需要对android c2dm服务进行一些说明。我有一个需要注册才能接收推送通知的应用程序。我的问题是,接收通知代码是否与应用程序一样是eclipse中同一项目的一部分。如果在这种情况下,如果项目不再运行且应用程序处于“关闭”状态,则应用程序将收到推送通知。 提前致谢     

解决方法

第一个答案是“是”,您可以编写推送通知接收代码作为应用程序的一部分。 第二个答案是。您将在应用程序打开或关闭时收到通知。 设备收到消息后将调用以下功能。您可以编写所需的任何操作。
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
        }
    }
以下链接可能有帮助 http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html