Howto passes an argument to an Android application that runs through a shell command

I have a command that launches an android app (apk) for a shell that works fine.

shell am start -a android.intent.action.VIEW -n mypackage/.MyActivity

How do I pass an argument to this command, which I can read in my application again?

shell am start -a android.intent.action.VIEW -n mypackage/.MyActivity <MyArgument>

and how to read a parameter in activity?

sMyParam = getIntent().getExtras().getString("MyArgument");
+4
source share
2 answers

Read the intent documents with shell commands .

The most likely bits for 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. 
+3
source

According to this document, you can use the option -efor String.

shell am start -a android.intent.action.VIEW -e KEY VALUE -n mypackage/.MyActivity
+2
source

Source: https://habr.com/ru/post/1532655/


All Articles