我正在运行sdk中提供的示例gcm-demo-client (extras/google/gcm/samples/),并且不断收到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中遗漏了什么?如何才能使我的消息具有唯一性?谢谢你的帮助法布里斯
发布于 2012-08-02 23:11:22
这是因为在GCMIntentService中,它发送相同的消息,每个time.You都应该更改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。
https://stackoverflow.com/questions/11780333
复制相似问题