开发者

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

开发者 https://www.devze.com 2023-03-08 16:17 出处:网络
I am a new developer on the android and need some clarifications on the android c2dm service. I ha开发者_如何学运维ve an application that needs to register for receiving push notifications. My questio

I am a new developer on the android and need some clarifications on the android c2dm service. I ha开发者_如何学运维ve 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消