ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

data field values are converted to string #289

Closed varungupta85 closed 7 years ago

varungupta85 commented 7 years ago

I am using this package to send remote notifications to Android devices. I use the data field to send the notifications. I am observing that all the fields are received as strings in my app in the GcmListenerService even if some of the fields that I sent are integers or booleans. Is that expected?

eladnava commented 7 years ago

Yes, GCM/FCM stringifies your entire payload, including integers, booleans, arrays, and objects.

A workaround is to send data: {json: JSON.stringify(data)} and have your Java app parse the JSON string into an object: http://stackoverflow.com/a/36282596/1123355

Or simply work with the strings to convert them to your desired data type.