4 Replies Latest reply on Oct 19, 2016 7:46 AM by kerrishotts

    Flashlight switches off when barcode scanner opens camera

    ThamodharanK555

      up vote0down votefavorite

       

       

      I am developing a phonegap app which uses a barcode scanner plugin to scan. I usedhttps://github.com/phonegap/phonegap-plugin-barcodescanner for implementing barcode scanner and it works fine.

      I implemented the flashlight plugin with https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin.

      The functionality that I need to implement is, the flashlight of the mobile should automatically switch on when the scanning starts and should automatically switch off once the scan is complete.

      I tried the following code:

      <img class="mrg-bt" src="img/qr-scanner.png" onclick="scan();">

        function scan(){
        scanlight(true); //switch on flashlight
        window.plugins.barcodeScanner.scan(function(result){
        //scan success code
        scanlight(false);//switch off flashlight
        });
        }
        //flashlight function call
        function scanlight(enable) {
        window.plugins.flashlight.available(function (isAvailable) {
        if (isAvailable) {
        if (enable) {
        window.plugins.flashlight.switchOn(
        function () { },
        function () { }, 
        { intensity: 0.3} 
        );
        } else {
        window.plugins.flashlight.switchOff();
        }
        }
        });
      }

       

      The issue is, the functionality is happening quite opposite to my requirement. When I hit the scan button the flashlight gets on and after the camera opens the flashlight goes off and the flashlight gets on once the camera is closed.

      Someone please help me to get rid of this. Thanks in advance.