I am working with the \"new\" GCM, part of Google Play Services, that does not use jars for both Android and server. Android uses Google Play apk to register, receive and even s
Is there a way to get, in Android end, payload information the way I've sent to GCM server?
Rather than thinking "JSON", think "key/value pairs". Your server sends data in key/value pairs. Your app receives that data as key/value pairs in the extras in the Intent
. You know what your keys are, so just retrieve the values out of the extras that are tied to those keys (e.g., getStringExtra("message")
, getStringExtra("url")
).
Or should I parse received data in Android without JSON?
The received data is not in JSON.
This is what I did to get the data ...I think this will help you..
This is the response I am getting from UrbanAirship push notification.
Bundle[{com.urbanairship.push.ALERT=, content-available=1, newscategorycode=O21R97, priority=5, com.urbanairship.push.PUSH_ID=afc9e690-f308-11e4-af8c-001018957618, id=6534.0, from=966150816212, func=News, newscategory=HR, com.urbanairship.push.APID=28e48c60-324b-456c-95b5-8fde9ab1a956, collapse_key=do_not_collapse, com.urbanairship.push.CANONICAL_PUSH_ID=7641453d-9207-4213-81c0-404387583de7}]
Solution:
Bundle bundle = message.getPushBundle();
in your case get the bundle object then use like this...
String func = bundle.getString("func");
String newscategory = bundle.getString("newscategory");
String sinceId = bundle.getString("id");
you will get the data..
Happy coding!
You have to add another level to json data, apparently they do not parse json recursively. Send:
{...., "data":{"payload":{"id":5,"a":5}}}
Then in code:
String json = intent.getExtras().getString("payload");
// json = {"id":5,"a":5}
This can be easily converted to POJO, For me this approach is better if you have classes already ( or just want to work with objects instead of get...("xyz")