简体   繁体   中英

How can I view and log full structure of GCM message in Android?

I want to debug GCM messages which receives my application but the problem I can't log fields outside the data array: collapse key , time-to-live , etc. GCM message which comes from the server is look like this:

{
 "registration_ids" : ["xyz"],
"data" : {
text: {...}
 },
"time_to_live" : 3
},

For debugging purposes i want to log time-to live parameters and others.But when I do this: String text = intent.getExtras().getString("text"); I can only view what is inside data. How can I view all the GCM message structure?

I don't believe you can. The parameters outside of data are not part of the notification payload. It's quite reasonable to believe that they are not even passed by the GCM server to your application. These outside params' only purpose is to tell the GCM server how to deliver the message (whether to send it to an idle device, how long to keep it in the GCM server when the device is not available, whether to override older undelivered messages that have the same collapse key, etc...).

EDIT :

Handling Received Data

The com.google.android.c2dm.intent.RECEIVE intent is used by GCM to deliver the messages sent by the 3rd-party server to the application running in the device. If the server included key-pair values in the data parameter, they are available as extras in this intent, with the keys being the extra names. GCM also includes an extra called from which contains the sender ID as an string, and another called collapse_key containing the collapse key (when in use).

From this quote, it seems you can also retrieve the collapse_key and the sender ID in addition to the key/value pairs inside data .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM