我試圖在我的應用中實施Google雲消息傳遞。但我仍然無法弄清楚爲什麼我沒有把正確的信息傳給我的手機。我的服務器發送消息,GCM服務器響應到併發送一條信息給我phone.This消息看起來像這樣GCM服務器返回空值
{\"multicast_id\":8186678237008516542,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1356727074650189%12aaaeccf9fd7ecd\"}]}"
我想這意味着我得到一個消息,問題是我唯一的應用展示空值。我現在正在使用瀏覽器的Api鍵,並獲得這些結果,但我試圖使用服務器密鑰(理論上它更適合我的需要),但我得到錯誤401.
爲了接收消息,我使用廣播接收機
public void onReceive(Context context, Intent intent){
String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);}
EXTRA_MESSAGE =消息
這是我在服務器上使用的代碼。
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_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);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
有誰知道這個問題可能是什麼?
正是你在哪裏顯示,空值? –
將null值返回給模擬器中的android應用程序 – user1732457
您是否認爲將信息包含爲顯示問題的代碼或異常的logcat跟蹤會很重要? –