I have a problem that involves sending intent containing string extra with space characters using Activity Manager on Mac OS X terminal.
Following command:
adb shell am start -n com.example.package/.Activity -e 'KEY' 'String with spaces'
...gives:
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=with cmp=com.example.package/.Activity (has extras) }
...and only "String" is actually passed to the Activity.
I can fix that by escaping spaces with backslashes:
adb shell am start -n com.example.package/.Activity -e 'KEY' 'String\ with\ spaces'
...gives:
Starting: Intent { cmp=com.example.package/.Activity (has extras) }
...and "String with spaces" is passed to the Activity, so it works as intended.
Problem is that escaping spaces brakes my script's compatibility with Ubuntu terminal. In such a case on Ubuntu "String\ with\ spaces" is passed to the activity.
Is there any way to force Mac OS terminal to interpret string extra containing spaces as Ubuntu terminal does?
I figured it out with the help from one of my teammates. It's Ubuntu terminal that has it wrong actually. In first case single quotes are stripped by local shell before sending the command to adb shell. That's why in device shell it executes:
am start -n com.example.package/.Activity -e KEY String with spaces
...and the result is as one may expect.
One solution to the problem can be wrapping the whole command supposed to be executed in device shell with single quotes and use double quotes to wrap strings, like this:
adb shell 'am start -n com.example.package/.Activity -e "KEY" "String with spaces"'
This works as expected on both Ubuntu and Mac terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With