我在 2020 年在我正在回收的“旧”设备(android KitKat 4.4)上面临同样的问题,这个问题首先出现在 Google 上。
所以看起来至少有两种方法可以调用相机应用程序(回到 android 4.4):(IMAGE_CAPTURE
你叫什么)和STILL_IMAGE_CAMERA
.
第一个在发送后要求确认adb shell input keyevent KEYCODE_CAMERA
,我找不到发送验证拍摄的密钥。因此照片不会被保存。
后者不要求确认,直接保存图片。因此,作为结论,这里是我输入的所有在我的KitKat手机上拍照的行(替换 :IMAGE_CAPTURE
为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
以及相应的单线:
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"
如果它仍然不适合您,请继续阅读:
事实上,我忽略了 Pragy Agarwal 的评论,因为它首先不起作用。它没有工作,因为手机屏幕关闭了。所以必须先按下电源键才能打开屏幕(但如果它已经按照此处的建议打开,则不要按下它):
adb shell dumpsys power | grep "mScreenOn=true" | xargs -0 test -z && adb shell "input keyevent KEYCODE_POWER"
如果对我来说它仍然无法工作,因为相机应用程序以某种方式显示最后一张拍摄的照片,你必须在进入相机应用程序时首先按下后退按钮:
adb shell input keyevent KEYCODE_BACK
所以总而言之
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
变成:
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"
对于一个 7 岁以上的设备来说,这是一个多么长的答案,但仍然以某种方式完成它的工作!