Hi.

I'm currently trying to use the Google Cloud Messaging service.
First I tried to write my own code, looking at the Android doc tutorial, 
but it did not work.
So I finally decide to directly try the demonstration client of GCM, and to 
write a simple PHP sender to test the messaging service.

My application resgisters succesfully : the callback is called and a regId 
is returned the first time I run the application. Then I copy/paste the 
regId in my PHP page which looks like this :

<?php

 $url = 'https://android.googleapis.com/gcm/send';
 $serverApiKey = "xxxxxxxx";   // the key from the API console
 $reg = "xxxxxxx"; // the regId from the registration callback

$headers = array(
 'Content-Type:application/json',
 'Authorization:key=' . $serverApiKey
 );

 $data = array(
 'registration_ids' => array($reg)
 , 'data' => array(
 'type' => 'New'
 , 'title' => 'GCM'
 , 'msg' => 'Msg received'
 )
 );

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 if ($headers)
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

 $response = curl_exec($ch);

curl_close($ch);
 print ($response);
?>

When I run the PHP code, the POST answer is something like :

{"multicast_id":5901247552211437983,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1348217100335906%921c249af9fd7ecd"}]}
 

And I think it seems to be a success answer, no ?

But nothing append on the device : in debug the breakpoints in the callback 
are not activated and the log lines I've added are never displayed in the 
traces. I think there is something that I've not understood at all about 
GCM. Any idea ?

(the gcm-client code is the sample provided with the GCM distribution, 
where I have suppressed the access to the third party registration server)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to