서버에 다시 게시되어 DB에 저장된 기기의 GCM 등록 ID가있는 경우 밀어 넣기 알림을 보내려고 할 때 데이터를 GCM 서버에 전달하면됩니다. 여기 예를 들어
내가 푸시 알림을 보낼 때 사용하는 기능입니다 :
//reg array here is an array of the GCM_reg_Ids I wish to send the push to
function push($regarr)
{
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
// Google API KEY, If you don't know your key just walk through the starter guide
$apiKey = "***************";
// Get all the message variables
// These are variables of data you send in the push notification which you use in the
// Appcode to do stuff
$message = "test" ;
$data = "http://www.google.com";
$preheader = "New Notification";
$header = "test" ;
$fields = array(
'registration_ids' => $regarr,
'data' => array("message" => $message,
"preheader" => $preheader,
"header" => $header,
"data" => $data),
);
$headers = array(
'Authorization: key=' . $apiKey,
'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);
$json_return = json_decode($result);
return $json_return;
}
당신이 CURL이 PHP에서 활성화되어 있는지 확인하는 것을 잊지 마세요 이 예제와 함께 거기에 가이드의 할당한다있다 및 GCM, 행복한 푸시 메 시징 시작하기 : D
시작하기 가장 좋은 장소는 공식적인 예입니다. 서버 부분과 클라이언트 부분을 설명합니다. 그래서 네, 당신은 당신의 안드로이드 프로젝트에서 뭔가를해야합니다. [예제] (http://developer.android.com/google/gcm/demo.html) – wtsang02
애플리케이션의 서버 부분에 대한 책임은 무엇입니까? –