Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – Trying to setOnKeyListener on camaraX

Posted on November 14, 2022

Solution 1 :

You can register a broadcast receiver to receive a callback every time the volume button is pressed, then trigger an image capture each time. You can take a look at how the CameraX sample implements this.

The broadcast receiver will look as follows. Make sure to register and unregister it appropriately.

private val volumeDownReceiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        when (intent.getIntExtra(KEY_EVENT_EXTRA, KeyEvent.KEYCODE_UNKNOWN)) {
            KeyEvent.KEYCODE_VOLUME_DOWN -> // Trigger an image capture
        }
    }
}

Since -it seems- you’re using CameraX’s CameraView API, you can trigger an image capture by calling one of its takePicture methods.

  • takepicture(Executor, OnImageCaptureCallback)
  • takePicture(OutputFileOptions, Executor, OnImageSavedCallback)

The image capture should only occur after the camera has been set up.

Problem :

I’m trying to make an app take a picture when the volume buttons are pressed, like snapchat and the like do. This app is using the CamaraX Library for camera functionality. Now as far as I can tell the CameraXView should let me set an onKeyListener as it extends frameLayout -> ViewGroup -> View. However, everything I’ve tried so far does not pick up the KeyEvents.

public class CameraXFragment extends LoggingFragment implements CameraFragment {
  ...
  private CameraXView          camera;
  ...
  private void initControls() {
    ...
    // This doesn't work
    camera.setOnKeyListener((v, keyCode, event) -> {
      Log.e(TAG, "KeyEvent please: " + keyCode);
      return false;
    });
    ...
    // This does work
    camera.setOnTouchListener((v, event) -> gestureDetector.onTouchEvent(event));
  }
}

CameraXView does have a onTouchEvent so I tried adding a onKeyDown within it as well but that doesn’t seem to have worked.

The camera.setOnTouchEventLister was not added by me so I don’t fully understand why that is working but mine isn’t.

READ  [ANSWERED] json - How to add values to JSONObject on button click in android?
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress