Send data back to the script which started the activity via adb shell am start
If the data that you want to send back to your automation script could be serialized into a string less than 4k long - using logcat
is a natural choice.
Just make your activity to print the data to the log with Log.i("UNIQUE_TAG", the_data_string_you_want_to_send_back_to_your_script);
and then use the following commands in your automation script to capture the output:
# clear the logcat buffer
adb logcat -c
# start your activity
adb shell am start <INTENT>
# this line will block until a string with "UNIQUE_TAG" tag and "Info" priority
# is printed to the main log
adb shell 'logcat -b main -v raw -s UNIQUE_TAG:I | (read -n 1 && kill -2 $((BASHPID-1)))'
# now you can capture the data and process it
DATA=$(adb logcat -d -b main -v raw -s UNIQUE_TAG:I)
In more recent Android versions (7.0+) where logcat
properly supports -m <count>
, -t <time>
and -T <time>
parameters you can use this much simpler version without having to clear the log with logcat -c
first:
# instead of clearing the log just get the current timestamp
TS=$(adb shell 'echo $EPOCHREALTIME; log ""')
# start your activity
adb shell am start <INTENT>
# this command will return immediately if the data has been printed already or block if not
DATA=$(adb shell "logcat -b main -T $TS -m 1 -v raw -s UNIQUE_TAG:I")
Is it possible to start activity through adb shell?
Launch adb shell and enter the command as follows
am start -n yourpackagename/.activityname
Use android adb shell to return one activity
you might want to try:
adb shell input keyevent KEYCODE_BACK
cf. KEYCODE_BACK event
How to start an application using Android ADB tools
adb shell
am start -n com.package.name/com.package.name.ActivityName
Or you can use this directly:
adb shell am start -n com.package.name/com.package.name.ActivityName
You can also specify actions to be filter by your intent-filters:
am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName
Get result value from intent in terminal
You can either implement a method returning a value in your service which you will call with service call
command or you can print the value into the log and then parse the logcat
output for the result.
Related Topics
How to Convert Ppi into Dpi for Android Images
Android: Android.Content.Res.Resources$Notfoundexception: String Resource Id #0X5
Android - Volume Buttons Used in My Application
Setting Drawable Folder to Use for Different Resolutions
Manually Put Files to Android Emulator Sd Card
Detecting When User Has Dismissed the Soft Keyboard
How to Change a Layer-List Drawable
Android - Getting Audio to Play Through Earpiece
How to 'Gettopactivity' Name or Get Currently Running Application Package Name in Lollipop
Import .CSV File to SQLite in Android
Creating a Directory in /Sdcard Fails
How to Find MAC Address of an Android Device Programmatically
Set the Layout Weight of a Textview Programmatically
Manually Put Files to Android Emulator Sd Card
Preventing Status Bar Expansion
Disable the Notification Panel from Being Pulled Down
How to Use a Compound Drawable Instead of a Linearlayout That Contains an Imageview and a Textview