Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send String[] intent extra value from command line?

My automated test sends intents via adb shell am, but I'm having trouble specifying an extra that is a String Array.

According to the Intent class docs, it is possible to put an String[] extra to an intent.

However the Intent specification docs for the am command does not list a string array type. The only string types I can see in the docs is normal string and perhaps null "string":

--esn <EXTRA_KEY>
    Add a null extra. This option is not supported for URI intents. 
-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>
    Add string data as a key-value pair. 

Is it avoidable to write a java application for the mere purpose of sending string arrays?

Is there a way to send a String[] extra from the command line?

edit in case this is not possible this way, what is the preferred way to do this?

like image 391
n611x007 Avatar asked Nov 04 '13 14:11

n611x007


People also ask

How do I set extras intent?

Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.

What is put extra in intent?

Using putExtra() and getExtras() in android Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. For example an Activity can send an Intents to the Android system which starts another Activity .

How pass data from one activity to another without using intent?

This example demonstrate about How to send data from one activity to another in Android without intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is the maximum data size that can be passed in an intent?

The Binder transaction buffer has a limited fixed size, currently 1MB, which is shared by all transactions in progress for the process.


2 Answers

Old question, but unanswered.
adb shell am shows all the options, among them there's:

[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
    (to embed a comma into a string escape it using "\,")
like image 102
Amir Uval Avatar answered Oct 04 '22 20:10

Amir Uval


For anyone else looking for this the command line flags for extras are listed below

-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>
--esn <EXTRA_KEY>
--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...]
like image 28
sean loyola Avatar answered Oct 04 '22 22:10

sean loyola