Search code examples
androidadb

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


When I want to send an Intent with a String extra via adb shell, I can do it this way:

adb shell am broadcast -a <intentAction> -d <intentDataUri> -f 0x10 -es <extraName> <intentExtraString>

In my App, I can read it using

String myString = intent.getStringExtra("<extraName>");

There are pairs for the following types documented:

  • --es and getStringExtra(...)
  • --ez and getBooleanExtra(...)
  • --ei and getIntExtra(...)
  • --el and getLongExtra(...)
  • --ef and getFloatExtra(...)
  • --eu and ??? (Uri)
  • --ecnand ??? (ComponentName)
  • --eiaand getIntArrayExtra(...)
  • --elaand getLongArrayExtra(...)
  • --efaand getFloatArrayExtra(...)

I need an Intent with a byte[] extra. I can get it with getByteArrayExtra(...), but how can I set it?

I've tried --eba, --eya, --eta and --eea. Everything unknown to the program. Just using --eia does not work as well: Then the result of getByteArrayExtra(...) is null.

Edit: Sending intent with bundle using console is not a duplicate of this question. It involves Bundles, no byte arrays.


Solution

  • It seems that there is no option for byte array extra.

    Details: https://developer.android.com/studio/command-line/adb#IntentSpec

    Do you really need to send intent by byte array? How about send it by "integer array extra", and cast it to byte?