3

In my GcmListenerService I am getting this bundle data:

Bundle[{gcm.notification.e=1, gcm.notification.title=SomeApp, proceed=true, gcm.notification.body=Some text, message=Some message, collapse_key=example.com.SomeApp}]

I am can get the message by

bundle.getString("message");

But i cannot get the proceed boolean value int the bundle data. I used:

bundle.getBoolean("proceed",false);

this is always giving false, even when the value is true in the bundle data. It is so simple, i don't know what i am missing. Thanks.

ArJ
  • 395
  • 5
  • 14

1 Answers1

4

Even though the value of proceed looks to be a boolean it is likely stored in the Bundle as a String and that is why you cannot get the value of it using bundle.getBoolean().

You should use bundle.getString("proceed"); instead.

You can parse the String into a boolean if you need to.

boolean proceed = Boolean.parseBoolean(bundle.getString("proceed", "false"));
George Mulligan
  • 11,813
  • 6
  • 37
  • 50
  • thanks, it is working now. But i was sending it as a boolean to gcm server by php. so i thought it would remain boolean. – ArJ Apr 19 '16 at 15:07
  • 2
    I can see the confusion there. I tried finding somewhere in the documentation whether or not it said all values are sent as Strings but didn't find much. The `onMessageReceived` says the `Bundle` is `message data as String key/value pairs`. Not sure if that means always `String` for both key and value. – George Mulligan Apr 19 '16 at 15:17