I have a couple of questions regarding GCM.
Decide which Google-provided GCM connection server you want to use— HTTP or XMPP (CCS).
Now I understand the difference between the two of these in practice, but when he says DECIDE which one to choose, I am not sure what is he expecting of me? Is there something I need to do differently for the two of these. https://android.googleapis.com/gcm/send
nd pass parameters along? I can use HTTPClient for this one, right? Is there something special? 2 - that's basically it, here' my server code, it's a PHP file in my server
public function send_push(){
$message = "your message";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => array("GCM_REGISTRATION"),
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=YOUR_API_KEY',
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
echo $result;
}
GCM_REGISTRATION is the hash you get after you run your app for the first time to register in GCM. if everything is ok, You can see this in logcat
api_key is the hash you get when you create your app( you have probably seen it on the documentation)
3 - I believe it doesn't need to be a server because it's actually going to send the message to Google servers which is going to deliver it to your app
Yes, there's a big difference between http and ccs severs. The former involves simple http requests. The latter requires xmpp protocol implementation.
Yes, any code that submits http requests should work if you are taking the gcm http approach.
For testing purposes you don't need a server. Any code submitting http requests would do. However, you'll have to pass the device registration id to your server code in order to send a GCM message.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.