Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto send a parameter when executing a android app with adb.exe shell command

Tags:

java

android

adb

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();
like image 984
mcfly soft Avatar asked Jun 20 '14 07:06

mcfly soft


People also ask

What is the use of adb shell command?

Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.


1 Answers

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")
like image 174
Vladimir Petrakovich Avatar answered Oct 19 '22 11:10

Vladimir Petrakovich