如何从接收方的gcm获取messageId

时间:2014-08-22 02:44:18

标签: android google-cloud-messaging messageid

我可以成功运行gcm的客户端和服务器。但是当我从服务器端发送消息时,我可以从gcm获取messageId,这是这样的:  0:1408673696996426%921c249a002efde3

但是,我无法从客户端(android端)获取此消息。通过监听onMessage事件,我可以从intent中检索消息数据,而我的onMessage代码是这样的:

protected void onMessage(Context context, Intent intent) {
    Log.i(TAG, "Received message");
    //JSONObject jsonObj = null;

    String datastr = intent.getExtras().getString("message");
    String message = "";
    if(datastr!=null)
        message = datastr;
    else
        message = getString(R.string.gcm_message);
    displayMessage(context, message);
    // notifies user
    generateNotification(context, message);
}

但是,我无法从意图中获取messageId。我搜索了official tutorial和其他论坛,但我没有得到答案。因此,我无法验证客户端是否已收到此消息。谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

此消息ID未传递给客户端。如果您希望能够确认消息传递,则可以将自己的ID分配给GCM消息,并在有效负载内传递它。然后,客户端可以将该ID发送回服务器以确认传送。

相关问题