androidgoogle-cloud-messagingandroid-bundlegcmlistenerservice

Android cannot get boolean value from bundle


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.


Solution

  • 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"));