Search code examples
androidandroid-c2dm

Does the c2dm code have to be written in the same application that registers for it?


I am a new developer on the android and need some clarifications on the android c2dm service. I have an application that needs to register for receiving push notifications. My question is whether the code to receive the notifications be a part of the same project in eclipse as the application. If in that case will the application receive the push notification if the project is no longer running and the application is "off".

Thanks in advance


Solution

  • First answer is "Yes" you can write push notification receiving code as part of your application. Second Answer is. You will receive notification weather your application open or close.

    Following function will call when device receive Message. You can write any action that you want.

    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
            }
        }
    

    Following link may help http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html