Search code examples
javaandroidzxingqr-codebarcode-scanner

How to start Scanner using the Flashlight with ZXing?


I want to make a QR Code scanner using ZXing library. In my build.gradle, I have added the following code:

repositories {
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}

dependencies {
    compile 'com.google.zxing:core:2.2'
    compile 'com.embarkmobile:zxing-android-minimal:1.2.1@aar'
}

and when I click on a Button, it executes the following code:

IntentIntegrator.initiateScan(MainActivity.this);

and the QR-Scanner scanner works.

Now, I want start the Scanner with the flash light. How can I do this? I've searching around the web, but examples confused me.

So, how can I start the Scanner using the flash light?


Solution

  • Source Code

    https://drive.google.com/open?id=0BzBKpZ4nzNzUN3RyeGtuUGpHQnc

    enter image description here

    Add Dependency in Manifest File - It's Working

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                CameraManager camManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
                String cameraId = null; // Usually back camera is at 0 position.
                try {
                    cameraId = camManager.getCameraIdList()[0];
                    camManager.setTorchMode(cameraId, false);  
    
     // TODO  Turn ON  Flash Light On
                    mScannerView.setFlash(true);    
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }