2012-08-02 95 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