无法在Android GCM中接收服务器发送的消息
作为参考,我一直在尝试实现Android GCM服务。我可以在数据库中注册emulator,但emulator不会收到从服务器发送的任何消息。有人能告诉我哪里出了问题吗?运行下面的PHP文件无法在Android GCM中接收服务器发送的消息,android,broadcastreceiver,google-cloud-messaging,Android,Broadcastreceiver,Google Cloud Messaging,作为参考,我一直在尝试实现Android GCM服务。我可以在数据库中注册emulator,但emulator不会收到从服务器发送的任何消息。有人能告诉我哪里出了问题吗?运行下面的PHP文件 <?php //request url $url = 'https://android.googleapis.com/gcm/send'; //your api key $apiKey = 'YOUR API KEY'; //registration ids $registrationIDs
<?php
//request url
$url = 'https://android.googleapis.com/gcm/send';
//your api key
$apiKey = 'YOUR API KEY';
//registration ids
$registrationIDs = array('First_Reg_Id','Second_Reg_Id','Third_Reg_Id');
//payload data
$data = array('title' => 'hi', 'message' => 'Push notification');
$fields = array('registration_ids' => $registrationIDs,
'data' => $data);
//http header
$headers = array('Authorization: key=' . $apiKey,
'Content-Type: application/json');
//curl connection
$ch = curl_init();
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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
print_r($fields);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
在此之前,请替换google提供的API密钥。用仿真器的注册码替换第一个\u Reg\u ID。如果未使用,请移除其他
您只需要运行这个PHP文件,就会得到带有标题和消息的消息。只需解析它。在真正的设备中尝试。它不会。还有其他建议吗?有没有人对此编码有类似的问题?你可以发布你的代码吗?它与链接中的相同。我没有对它做任何更改。服务器和客户端的代码都是相同的。@MradulModi您能帮我一下吗?我正在使用相同的代码,但无法在emulator上运行它?即使在真实的设备中,我也获得了注册id,但无法从服务器发送通知。请指导我