Android Question How to simulate volume key press inside camera

Inman

Well-Known Member
Licensed User
Longtime User
Most camera apps have an option to take a photo when volume buttons are pressed. I am trying to implement a background service that will send Volume Down keypress when the camera app is open. Here is what I tried so far for testing.
  • Create a service that has a SendInput object running inside a timer every 3 seconds
  • SendInput.SendKeyCode(KeyCodes.KEYCODE_VOLUME_DOWN) is called inside the timer
  • Before opening camera app, I can see this timer working as the device volume is decreasing. I also have a log message inside timer that confirms the same
  • When Camera app is opened, I can see the log message indicating timer is executed but nothing is happening
  • If I press the Volume button, the camera app takes a photo
Theoretically if physical Volume button click takes a photo, the SendInput should also work. But it doesn't. The author of the library doesn't seem to be active anymore.

So any idea why the Volume button click emulation is not working in camera app?
 

Inman

Well-Known Member
Licensed User
Longtime User
I was thinking that you could detect the button press and then handle the rest yourself, that's if there's no easier way to do what you want, as there's bound to be @Inman
Actually what I want to do is click a photo using camera app when certain conditions are satisfied. I don't need the actual picture file or anything; I just need to click the photo using camera app. Since there's no way to click the trigger button on another camera app, I thought the next possible solution will be to simulate volume button press.
 
Upvote 0
Top