adb shell escape character for comma

2019-05-30 23:09发布

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

标签: android adb
2条回答
成全新的幸福
2楼-- · 2019-05-30 23:27

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

查看更多
孤傲高冷的网名
3楼-- · 2019-05-30 23:38

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"}]}'
查看更多
登录 后发表回答