Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto pass an argument to an android app, which is started through shell command

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");
like image 369
mcfly soft Avatar asked Mar 20 '14 11:03

mcfly soft


Video Answer


2 Answers

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. 
like image 145
zmarties Avatar answered Oct 21 '22 03:10

zmarties


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
like image 39
Zohra Khan Avatar answered Oct 21 '22 03:10

Zohra Khan