2012-08-02 99 views
2

我正在運行sdk(extras/google/gcm/samples /)中提供的示例gcm-demo-client 並繼續收到key1 =「From GCM:you got message!」從收到的意圖, 即使我發佈不同的值。收到相同的消息

例如,當我發佈了以下機身

{ 
    "data":{"key1":"value1","message":"this text will be seen in the notification bar!!"}, 
    "registration_ids":["$GCM_REGISTRATION_ID"] 
} 

我收到與總是相同的MESSAGE_ID響應

{ 
    "multicast_id":4767008207494821680, 
    "success":1,"failure":0, 
    "canonical_ids":1, 
    "results":[{"registration_id":"APA91bH7p....f1tT65n3A","message_id":"0:1343892969659984%921c249af9fd7ecd"}] 
} 

我是怎麼在API中錯過?我怎樣才能讓我的信息獨一無二? 感謝您的幫助 Fabrice

回答

3

這是因爲在GCMIntentService中它每次都會發送相同的消息。您應該更改GCMIntentService中的以下方法。

@Override 
protected void onMessage(Context context, Intent intent) { 
    Log.i(TAG, "Received message"); 
    String message = getString(R.string.gcm_message); 
    displayMessage(context, message); 
    // notifies user 
    generateNotification(context, message); 
} 

而不是

String message = getString(R.string.gcm_message); 

你應該從下面的意圖

String message = intent.getExtra("message"); 

顯示更多信息讀取的數據處理接收到的數據部分here

+1

parvin, 非常感謝 – user1571783 2012-08-02 16:50:36