zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

How to switch to Front camera and back to Back camera

Open giangmd opened this issue 4 years ago • 3 comments

Hello, I am implement the switch button for switching Back <=> Front camera. How do we set it with Java code?

giangmd avatar Jul 02 '20 17:07 giangmd

I did it like this. readerView.pauseAndWait(); CameraSettings s = new CameraSettings(); try { if (switchCamera) { s.setRequestedCameraId(1); frontCameraFab.setBackgroundTintList(ColorStateList.valueOf(context.getColor(R.color.golden))); } else { s.setRequestedCameraId(0); frontCameraFab.setBackgroundTintList(ColorStateList.valueOf(context.getColor(R.color.transparent_mask_overlay))); } readerView.getBarcodeView().setCameraSettings(s); switchCamera = !switchCamera; } catch (Exception e) { Log.i("TAG", "onClick: " + e.getMessage()); }

dan15h avatar Oct 09 '20 06:10 dan15h

It didn't work, is there any other way?

huangShan-gitHub avatar Dec 07 '22 05:12 huangShan-gitHub

this is what i have tried and worked for me private var isFrontCamera = false

isFrontCamera = if (!isFrontCamera) { barcodeView!!.pauseAndWait() barcodeView!!.cameraSettings.requestedCameraId = 1 barcodeView!!.resume() true } else { barcodeView!!.pauseAndWait() barcodeView!!.cameraSettings.requestedCameraId = 0 barcodeView!!.resume() false }

abdlhay avatar Jan 14 '23 14:01 abdlhay