我已經寫了一個php代碼,使用GCM服務器向android移動設備發送推送通知。它的工作正常。現在我想發送大小圖片作爲推送通知。我怎麼做這是我的代碼。如何在android中使用GCM作爲推送通知發送小圖像和大圖像
<?php
// API access key from Google API's Console
define('API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE');
$registrationIds = array($_GET['id']);
// prep the bundle
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
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));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
只要發送你的'圖像link'在'推notification'並在接收器加載它。 –
是啊...我已經嘗試過..但它並沒有woking ..這是我的圖像鏈接''largeIcon'=>'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github -512.png'' –
您是否在接收器中獲得此鏈接?如果是,則顯示您的接收器。 –