yuriy-budiyev / code-scanner

Code scanner library for Android, based on ZXing
MIT License
1.09k stars 266 forks source link

Front camera #156

Open YousefMohammed0060 opened 2 years ago

YousefMohammed0060 commented 2 years ago

How to make the scan made by the front camera not the main camera.

Gl0deanR commented 2 years ago

Hi, when you create the codeScanner variable of type CodeScanner you can set the CAMERA_BACK or CAMERA_FRONT, like this:

private fun codeScanner() {
        codeScanner = CodeScanner(this, scannerView)

        codeScanner.apply {
            // camera = CodeScanner.CAMERA_BACK // uses phone main camera
            camera = CodeScanner.CAMERA_FRONT // uses phone front camera
            formats = CodeScanner.ALL_FORMATS // supports all code formats available in the library

            autoFocusMode = AutoFocusMode.SAFE
//            scanMode = ScanMode.CONTINUOUS // keeps decoding codes until told otherwise via a button or some action
            scanMode = ScanMode.SINGLE // decodes the first code found and returns
            isAutoFocusEnabled = true // enables auto focus mode as default
            isFlashEnabled = false // false means flash light is off, true means it is on
        }
}

hope this helps!

vishalvala commented 2 years ago

in java project it's not working. i also try to change camera but not working. i don't know in kotlin project work or not. i working on android 10 version.

AsadKhanisonline commented 1 year ago

You can use camera ID like codeScanner.setCamera(1);

but you have to do it by onclick inside a button or icon