zxing-android-embedded
zxing-android-embedded copied to clipboard
How to switch to Front camera and back to Back camera
Hello, I am implement the switch button for switching Back <=> Front camera. How do we set it with Java code?
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()); }
It didn't work, is there any other way?
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
}