7

i start an android app with "adb.exe shell" as follow and this works fine:

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

How can I provide a parameter to the command and how can I read it in my app ?

shell am start -a android.intent.action.VIEW -n mypackage/.myActivity <PARAMETER>

public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       String myParameter=getHowtoReadaParamter();

1 Answer 1

20

From am help:

-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...
--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...
--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...
--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...
--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...
--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...
--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>
--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]
--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]
--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]

So you can send a string parameter like this:

shell am start -a android.intent.action.VIEW -n mypackage/.myActivity -e param value

and read it in activity:

getIntent().getStringExtra("param")
Sign up to request clarification or add additional context in comments.

1 Comment

what is value is something like this "Firstname Lastname"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.