我正在使用Adobe phonegap插件推送通知並開發android應用程序。使用Adobe Plugin的Phonegap Android推送通知
http://www.adobe.com/devnet/phonegap/articles/android-push-notifications-with-phonegap.html
服務器發送推送通知是PHP作爲
<?php
// Replace with real BROWSER API key from Google APIs
$apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// Replace with real client registration IDs
$registrationIDs = array("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
// Message to be sent
$message = "there is an update, waiting for you to install...";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array("message" => $message),
);
$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);
echo $result;
編譯Android的代碼我收到註冊成功與REGID後。
發送通知後的反應是成功的
{
multicast_id: 5022434288122138000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [
{
message_id: "0:1361774232591520%8eab850df9fd7ecd"
}
]
}
但仍我無法得到我的電話通知。
不知道我在做什麼錯。
編輯:
對不起,我聽明白了推送通知消息,但並沒有顯示它。現在
http://www.adobe.com/devnet/phonegap/articles/android-push-notifications-with-phonegap.html#articlecontentAdobe_numberedheader_4
對我的作品的期待!!:
對不起,我得到推送通知消息,但沒有顯示它。 – Pawan 2013-02-25 09:42:13
我無法發送通知到設備bcoz我寫的代碼就像你寫的代碼一樣,然後我上傳這個頁面到我的服務器,運行後我遇到了像「未經授權的錯誤401」的錯誤,請你幫幫我。這我的網址http://stackoverflow.com/questions/23677313/android-phonegap-send-push-notification-using-google-cloud-messaging-using-php – 2014-05-15 11:55:22