Hi,
I was trying to pass a JSON string to an Android activity using the "optionalIntentArguments" capabilities and was puzzled by the fact that only the first JSON parameter would end up in the activity intent extras.
# This is Python code
optionalIntentArguments = '-e user \'"\'{"username":"selenium","administrator":true,"objectId":"1","email":""}\'"\''
which ends up in the appium log as:
info: [debug] executing cmd: /home/jbl/adt/sdk/platform-tools/adb -s LGDXXXX shell am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n xx.xx.xx/xx.xx.xx.Activity -e user '"'{"username":"selenium","administrator":true,"objectId":"1","mobileUpdatedAt":"2015-07-03T09:31:08.194Z","hide_customers":false,"fullName":"selenium","email":""}'"'
This looks fine, but the extras getString("user") returns "username":"selenium"
which is wrong...
I immediately suspected quoting and tried various combinations of backslashes, single vs double quotes and couldn't for the life of me figure it out.
I got to a point where this worked when issuing the "am start" command from the ADB shell, but not from my computer's shell (which is similar to the appium scenario).
I searched around and found this, which put me on the right track to solve my issue:
See http://stackoverflow.com/a/29428061/1872442
I modified the _buildStartCmd function in https://github.com/appium/appium-adb/blob/master/lib/adb.js
to quote the entire adb command:
adb -s LGDXXXX shell am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n xx.xx.xx/xx.xx.xx.Activity -e user '"'{"username":"selenium","administrator":true,"objectId":"1","email":""}'"'
becomes:
adb -s LGDXXXX shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n xx.xx.xx/xx.xx.xx.Activity -e user '"'{"username":"selenium","administrator":true,"objectId":"1","email":""}'"'"
which works fine and doesn't seem to cause any other issue.
I'm currently working on a pull request for this...
Cheers,
JB