Search code examples
androidautomationcameraadb

Capture JPEG image on Android with specified name using adb and activity manager


Update I perfectly understand, that all applications are different, and there is no standard. I'm asking the following question in hope that it will be read by someone possessing knowledge of internals of Samsung camera apps.

I'm developing an automation tool, that should capture images using Android smartphone.

The smartphone is always connected to the PC using USB cable and is controlled by adb.

Up to now I've managed to launch camera application, send it KEYCODE_CAMERA event and pull the newest file in the default camera directory (/sdcard/DCIM/Camera):

adb am start -a android.media.action.STILL_IMAGE_CAMERA -n com.sec.android.app.camera/.Camera       # launch camera app.
adb shell input keyevent KEYCODE_CAMERA   # take a picture
adb shell ls -t /sdcard/DCIM/Camera | head -1   # determine name of newly created file

I don't like that I cannot turn off auto exposure and other "magic", enabled in Samsung camera apps by default. I also cannot control file name.

I've found another action, android.media.action.IMAGE_CAPTURE. When I launch intent with it, the camera app doesn't show any additional controls.

When I send KEYCODE_CAMERA event, it shows a preview of a captured image and two buttons "Repeat" and "Ok". This preview disappears after I issue KEYCODE_ENTER event.

However, I don't see any file with captured image.

Activity manager shows lots of command line switches when run without parameters, that suggest that it gives rich opportunities.

Is it possible to make the camera activity to save file?

I'm using Galaxy Tab S4 with Android 8.1, camera app version is 8.0.11.11


Solution

  • There are no standard adb options that allow you to control arbitrary camera apps to perform arbitrary actions. Similarly, there are no standard adb actions to print a file, start a dishwasher, or launch a rocket. All you can do with adb and the am command is craft an Intent — the details of what might be allowed in that Intent are up to the recipient of the Intent, as with all APIs ever created.

    Nobody, other than the developers of the camera app, know what undocumented and unsupported Intent options there might be for that app. Saying that it is a "Samsung" camera app merely limits the scope to a few dozen different pre-installed camera apps that Samsung has shipped over the years.

    You are certainly welcome to examine the source code to open source camera apps and see if any offer Intent options that would allow you to accomplish what you want via adb. However, there is no guarantee that those will remain unchanged as that camera app evolves over time.