Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing bundle from android push notification

I am using GCM to push notification to mobile using this example and the notification is pushed. But I could not able to parse the bundle received from intent. This is the bundle I got from log Bundle[{message={"valid":"bbb","deal":"its working","address":"some","name":"aaa"}, android.support.content.wakelockid=1, collapse_key=do_not_collapse, from=198162727742}] . and I converted it into string and then tried to convert to json object using this codejson = new JSONObject(message); but no luck. can anybody tell what I am doing wrong here. thanks in advance

like image 548
Mithran Avatar asked Jan 30 '14 13:01

Mithran


2 Answers

In the method that received the intent do this:

protected void onMessage(Context context, Intent intent) {
    //log the message in JSON format
    Log.i(TAG, "Received message >> " + intent.getExtras().toString());
    //Retrieve message and extra
    String message = intent.getExtras().getString("message");
}
like image 80
meda Avatar answered Nov 09 '22 12:11

meda


The real JSON Object is this:

{"valid":"bbb","deal":"its working","address":"some","name":"aaa"}

The rest is not actually JSON.

Try to parse just this line, and it will work =)

So:

json = new JSONObject( bundle.getString("message") );
like image 44
Reinherd Avatar answered Nov 09 '22 11:11

Reinherd