I have a command which starts an android app (apk) per shell command, which works great.
shell am start -a android.intent.action.VIEW -n mypackage/.MyActivity
How can I pass an argument to that command, which I can read in my app again ?
shell am start -a android.intent.action.VIEW -n mypackage/.MyActivity <MyArgument>
and howto read the parameter in the activity ?
sMyParam = getIntent().getExtras().getString("MyArgument");
Read the docs for specifying intents with shell commands.
The bits of most likely interest to you are:
-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>
Add string data as a key-value pair.
--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>
Add boolean data as a key-value pair.
--ei <EXTRA_KEY> <EXTRA_INT_VALUE>
Add integer data as a key-value pair.
As per this document you can use -e
option for String.
shell am start -a android.intent.action.VIEW -e KEY VALUE -n mypackage/.MyActivity
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