Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.4 won't allow me to save a picture when captured using adb commands

My objective is to automate the process of capturing and saving a picture, with both front and back facing cameras.

I am using a Nexus 5 running Android version 4.4.2 and I have not rooted it.

I use the following commands to open the front and rear facing camera respectively:

>adb shell am start -a android.media.action.IMAGE_CAPTURE --ei android.intent.extras.CAMERA_FACING 1


>adb shell am start -a android.media.action.IMAGE_CAPTURE --ei android.intent.extras.CAMERA_FACING 0

(I found these commands in a previous stackoverflow post-> ADB command to toggle camera modes in android device)

The problem is that while the device is in either of these modes, it will only capture and not save an image when I execute this command:

>adb shell input keyevent KEYCODE_CAMERA

Once I run this command, the photo appears on the screen along with buttons to save, discard or retake the photo. However the save option does not appear to do anything.

I have two specific questions:

1.) Are there any alternative commands that I can use to open either camera?

2.) How can I make sure that the image is not being saved in some unexpected location?

I would really appreciate some help with this issue.

Edit: I don't need to store the picture on my pc, i expected it to be in /sd/card/DCIM/Camera or somewhere else on the phone.

like image 678
user3416096 Avatar asked Mar 13 '14 18:03

user3416096


People also ask

What can I do with adb commands?

You can use ADB to install standalone APKs (Android app installation packages), move files between your computer and device, run shell commands, take screenshots (or record video of the screen), find detailed information about the device, generate bug reports, view system logs, and a lot more.


1 Answers

I am facing the same issue in... 2020 on an "old" device that I am recycling (android KitKat 4.4) and this question comes first on Google.

So it looks like there are at least 2 ways to call the camera app (back on android 4.4) : IMAGE_CAPTURE (what you called) and STILL_IMAGE_CAMERA.

The first one asks for confirmation after adb shell input keyevent KEYCODE_CAMERA has been sent and I could not find the key code to sent to validate the shooting. Consequently the photo is not saved.

The latter does not ask for confirmation and the picture is directly saved. So as a conclusion here are all the lines I input to take photos on my KitKat phone (replace : IMAGE_CAPTURE with STILL_IMAGE_CAMERA).

adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA"
adb shell "input keyevent KEYCODE_FOCUS"
adb shell "input keyevent KEYCODE_CAMERA" #actually takes photo and saves it

And the corresponding one-liner :

adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA" && sleep 1 &&  adb shell "input keyevent KEYCODE_FOCUS" && sleep 1 &&  adb shell "input keyevent KEYCODE_CAMERA"

If it still does not work for you, keep reading :

Indeed I overlooked Pragy Agarwal's comment because first it did not work. And it did not work because the phone screen was off. So the power key has to be pressed first to swtich the screen on (but not press it if it was already on as suggested here) :

adb shell dumpsys power | grep "mScreenOn=true" | xargs -0 test -z && adb shell "input keyevent KEYCODE_POWER"

And if as for me it still does not work because the camera app is somehow showing the last picture taken, you have to first press the back button when entering the camera app :

adb shell input keyevent KEYCODE_BACK

So all in all

adb shell dumpsys power | grep "mScreenOn=true" | xargs -0 test -z && adb shell "input keyevent KEYCODE_POWER" # switch the screen on

adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA"

adb shell input keyevent KEYCODE_BACK # go back to the "real time" camera not the gallery

adb shell "input keyevent KEYCODE_FOCUS"
adb shell "input keyevent KEYCODE_CAMERA" # shoots the picture and saves it

Which turns into :

adb shell "dumpsys power" | grep "mScreenOn=true" | xargs -0 test -z && adb shell "input keyevent KEYCODE_POWER" && sleep 1 && adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA" && sleep 1 && adb shell "input keyevent KEYCODE_BACK" && sleep 1 &&   adb shell "input keyevent KEYCODE_FOCUS" && sleep 1 &&  adb shell "input keyevent KEYCODE_CAMERA"

What a long answer for a 7+ year old device but still doing its job somehow!

like image 110
HelloWorld Avatar answered Oct 03 '22 02:10

HelloWorld