Android start flash in zxing library

2.2k Views Asked by At

i made an android app using zxing library for barcode scan. barcode reader start when i tap on button, this is the code:

//scan
    mScanBtn = (Button)findViewById(R.id.scan);
    mScanBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {

                Intent intent = new Intent(
                        "com.google.zxing.client.android.SCAN");
                intent.setPackage("com.app.myapp");
                intent.putExtra("SCAN_MODE", "ONE_D_MODE");
                startActivityForResult(intent, 0);

            } catch (Exception e) {

                e.printStackTrace();

            }
        }
    });

This code works fine and barcode scanner start. But i want to start also ledflashlight (if present) when barcode reader start. There is a way to start flashlight when zxing library start?

2

There are 2 best solutions below

3
Sean Owen On

No, you can't force the flashlight on when you start the app. The idea is that the user is in the best position to control whether it's on or not. I wouldn't want an app turning on a bright light in the wrong situation.

1
Neel Mevada On
 Camera camera  =Camera.open();
 Camera.Parameters p;
 p = camera.getParameters();
 p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
 camera.setParameters(p);

 CameraConfigurationUtils.setTorch(p,true);

Using this you can on the torch on android studio integrated dependicy library.