1

In android M, we can take a picture from default camera application when presses the Key volume down/up on the phone. By the observation, I want to take a picture by sending the key volume down/up action using code. This is my code but it is nothing happen when I ran it. How can I modify the bellow code such that it can take a picture?

Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CAMERA, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
sendOrderedBroadcast(downIntent, null);
Jame
  • 3,746
  • 6
  • 52
  • 101
  • "In android M, we can take a picture from default camera application when presses the Key volume down/up on the phone" -- there are thousands of Android device models, with hundreds of "default camera applications". None have to support taking a picture using a volume key, so even if one does, that only covers a few devices. "How can I modify the bellow code such that it can take a picture?" -- that should not be possible, as apps (other than via root) should not be able to simulate this sort of user input. – CommonsWare Nov 20 '16 at 14:32
  • But someone said to me it is possible and he was it. However, he did not provide the solution – Jame Nov 20 '16 at 15:02
  • Possible duplicate of [Android How to listen for Volume Button events?](http://stackoverflow.com/questions/9162705/android-how-to-listen-for-volume-button-events) – Bö macht Blau Nov 21 '16 at 09:12
  • Thanks but it is listen event. I want to perform the event – Jame Nov 21 '16 at 09:51

0 Answers0