条形码扫描器Cordova带LED灯

问题描述 投票:2回答:3

我使用插件com.phonegap.plugins.barcodescanner创建应用程序扫描二维码

但扫描时我无法打开设备中的led灯

如何解决问题

谢谢大家的帮助!

cordova cordova-plugins barcode-scanner flashlight
3个回答
4
投票

我找到了解决方案。

扫描时,如果要让LED灯亮起,请增加音量。 如果要关闭LED,请减小音量


0
投票

使用cordova-plugin-flashlight:

   function scanlicht(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();
              }
           }
        });
     }
    function scan(){
       scanlicht(true);
       cordova.plugins.barcodeScanner.scan(
          function (result) {
             scanlicht(false);
             .... your code ....
          }, function (error) {
             scanlicht(false);
             alert("Scanning failed: " + error);
          },null
       }
    }

0
投票

只需显示一个按钮即可打开割炬或打开Android割炬:

   cordova.plugins.barcodeScanner.scan(
      function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
      },
      function (error) {
          alert("Scanning failed: " + error);
      },
      **{
          showTorchButton : true, // iOS and Android
          torchOn: true, // Android, launch with the torch switched on (if available)
      }**
   );
© www.soinside.com 2019 - 2024. All rights reserved.