2

I am emulating a Broadcast Intent via ADB Tool, One of the intents extras value is a JASON, The Jason string is broken after the first comma and I'm not getting the rest of the string.

The shell command I am using:

adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -n com.example.fx/com.example.fx.utils.gcm.GcmBroadcastReceiver --es "custom" "{"time":"2014-12-08T15:11:19,event_type":"m","event_id":"1418051429_1418051479"}" 

The code I use to get the string from the intent :

String payload = intent.getStringExtra("custom"); 

The result I get:

 "time:2014-12-08T15:11:19" 

Does anyone know why this happens and a way around it?

Thanks in advance

1
  • 1
    adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -n com.example.fx/com.example.fx.utils.gcm.GcmBroadcastReceiver --es "custom" '{"time":"2014-12-08T15:11:19,event_type":"m","event_id":"1418051429_1418051479"}' Commented Dec 9, 2014 at 16:12

2 Answers 2

4

Had the same problem, solved it using Alex P.'s comment:

  1. Make sure you switch the " with ' and vice versa in you "raw" JSON strings.

  2. Make sure you're not using ` around your strings.

  3. Make sure that the outer-most "wrapper" of your string consists of '.

To summarize:

This didn't work:

... --es "data" "{'buttons': [{'interaction': 'open', 'label': 'Show'}, {'interaction': 'less', 'label': 'Less of this'}]}" 

This did work:

... --es "data" '{"buttons": [{"interaction": "open", "label": "Show"}, {"interaction": "less", "label": "Less of this"}]}' 
Sign up to request clarification or add additional context in comments.

2 Comments

Shouldn't --es "data" '{"buttons": [{"interaction": "open", "label": "Show"}, {"interaction": "less", "label": "Less of this"}]' be --es "data" '{"buttons": [{"interaction": "open", "label": "Show"}, {"interaction": "less", "label": "Less of this"}]}'? I believe there should be a closing parenthesis.
@Firelord Thank you for pointing that out. At first glance it seems to me that you're right and it is in fact a typo. I'll test this later just to make sure and will edit my answer accordingly. If you tell me your version works for you while my doesn't - this could be sufficient "proof". I think this happened because my "data" contains other keys besides 'buttons' so I didn't close the JSON object....
1

I had the same problem and worked around it by first running adb -e shell, and then sending my broadcasts from that session.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.