5

I know that you can start any exported activity from any app via adb using the following command:

am start -n com.myapp.test/.TestActivity

Using the "am start" command it is also possible to send extra data to the activity (I know how to do this, this is not the question I am asking here!).

However what I need to know is if it is also possible to receive the response data sent back from the started activity when it finishes?

Robert
  • 39,162
  • 17
  • 99
  • 152

2 Answers2

1

UPDATE You could print results to logcat. Just start with -W, so it waits for launch to complete

and then do a logcat -d

OP already has understanding for the following. I misread the question, keeping it just in case for somebody else who lands here

To send data to the activity
Please refer here for the intent specification.

You can pass in key value pairs.

To Quote from spec
-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> can be used to pass key string-value pair. There are other options to pass in different type of data

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mukul Goel
  • 8,387
  • 6
  • 37
  • 77
  • That was not a question, just a statement. I know how to do it. – Robert Apr 21 '16 at 12:07
  • @Robert: My bad man, I read "is it" instead of "it is". Honest mistake :D – Mukul Goel Apr 21 '16 at 13:21
  • @Robert: Please check the update. – Mukul Goel Apr 21 '16 at 13:30
  • Nice idea. I tested it with an self-written test app. Unfortunately it does not work because `-W`only waits until the new Activity has been started (not ended). Therefore the `am`process is long gone when the activity ends (by a button click). Also in logcat I do not see the activity result (unless I print it out in my test app). – Robert Apr 21 '16 at 14:54
  • @Robert: mmm.. yes, you would need to print it out explicitly to log and parse it out of there. Second, I think the activity would keep on writing to the logcat as it goes on. its just you need to check when the activity has finished. You could do something like: In the script, start the activity with `am start`. In your activity, in `onDestroy` output to log for example `finished`, then take the log between start and this string and parse for results.. Source: http://stackoverflow.com/questions/14715560/how-do-i-tell-if-an-android-activity-is-finished-from-an-external-adb-command – Mukul Goel Apr 21 '16 at 15:23
  • Ok, my example wasn't clear - my aim is starting an activity of a foreign app I don't have the source code. Otherwise I wouldn't had to use `am` for starting the activity. As I want to start a non-exported activity I have to use `su` and `am`. – Robert Apr 21 '16 at 17:23
0

A roundabout solution:

1,Write a tool-apk that can receive intent parameters, and use this parameters to startActivityForResult. when get the result, logcat it or write it to some file.

2, use adb to start this tool-apk use any intent parameters you want, than,periodically check the logcat or the file to get the result.

Swing
  • 858
  • 1
  • 8
  • 21