From a964e7f4e967af43414d0152db614add22105c5c Mon Sep 17 00:00:00 2001 From: sigbjornt Date: Mon, 18 Jul 2011 01:45:50 -0700 Subject: [PATCH 1/4] The example code should compile now... --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 0907c3c..9f1c7c7 100644 --- a/README.markdown +++ b/README.markdown @@ -29,7 +29,7 @@ To send a notification, you can do it in two steps: C2DMService service = C2DM.newService() - .withAuthToken(("serviceAuthenticationToken") + .withAuthToken("serviceAuthenticationToken") .build(); 2. Create and send the message From fda3542c204ea82197ae43ca5ad80cfd157cac88 Mon Sep 17 00:00:00 2001 From: sigbjornt Date: Mon, 18 Jul 2011 01:48:14 -0700 Subject: [PATCH 2/4] Added payload to the example --- README.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 9f1c7c7..3a6876c 100644 --- a/README.markdown +++ b/README.markdown @@ -35,8 +35,10 @@ To send a notification, you can do it in two steps: 2. Create and send the message C2DMNotification notification = C2DM.newNotification() - .collapseKey("daily_message").delayWhileIdle(true) - .build(); + .collapseKey("daily_message") + .data("payload", "Here be dragons (or another message)") + .delayWhileIdle(true) + .build(); String registrationId = "deviceRegistrationID"; service.push(registrationId, notification); From 5ba8835f377638ae83bdac3b9ddc8347179dae35 Mon Sep 17 00:00:00 2001 From: sigbjornt Date: Mon, 18 Jul 2011 01:49:26 -0700 Subject: [PATCH 3/4] Added example for recieving the payload on the client --- README.markdown | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 3a6876c..58e6e80 100644 --- a/README.markdown +++ b/README.markdown @@ -35,15 +35,27 @@ To send a notification, you can do it in two steps: 2. Create and send the message C2DMNotification notification = C2DM.newNotification() - .collapseKey("daily_message") - .data("payload", "Here be dragons (or another message)") - .delayWhileIdle(true) - .build(); + .collapseKey("daily_message") + .data("payload", "Here be dragons (or another message)") + .delayWhileIdle(true) + .build(); String registrationId = "deviceRegistrationID"; service.push(registrationId, notification); That's it! +On the device, you will be able to recieve the message by doing this: + + @Override + protected void onMessage(Context context, Intent intent) { + //Extract the payload from the message + Bundle extras = intent.getExtras(); + if (extras != null) { + System.out.println(extras.get("payload")); //Will print to the logcat + // Do something with the data you recieved + } + } + Features In the Making --------------------------- * Auto retries (exponential back-off feature) From 9d856afca390049c570e4f6d1335dae15da43fda Mon Sep 17 00:00:00 2001 From: sigbjornt Date: Mon, 18 Jul 2011 02:11:45 -0700 Subject: [PATCH 4/4] Added link to a stackOverflow question about where the serviceAuthenticationToken can be obtained from. --- README.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.markdown b/README.markdown index 58e6e80..a0ba371 100644 --- a/README.markdown +++ b/README.markdown @@ -41,6 +41,8 @@ To send a notification, you can do it in two steps: .build(); String registrationId = "deviceRegistrationID"; service.push(registrationId, notification); +(Read http://stackoverflow.com/questions/4164921/who-provides-auth-token-to-use-with-c2dm in order to get the serviceAuthenticationToken) + That's it!