Java – how to send parameters when executing an Android application using the adb.exe shell command
•
Android
I start an Android application with "adb.exe shell" as follows, which works normally:
shell am start -a android.intent.action.VIEW -n mypackage/.myActivity
How do I provide parameters to a command and read it in my application?
shell am start -a android.intent.action.VIEW -n mypackage/.myActivity <PARAMETER>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myParameter=getHowtoReadaParamter();
resolvent:
From my 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 in the activity:
getIntent().getStringExtra("param")
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码