【问题标题】:Barcodescanner cordova with led light带 LED 灯的条码扫描仪科尔多瓦
【发布时间】:2015-08-05 17:25:14
【问题描述】:

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

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

如何解决问题

感谢大家的帮助!

【问题讨论】:

    标签: cordova cordova-plugins barcode-scanner flashlight


    【解决方案1】:

    我找到了解决办法。

    扫描时,如果您希望 LED 灯亮起,只需增大音量即可。如果要关闭 LED 灯,请降低音量

    【讨论】:

    • 很好,它在安卓手机上运行良好,但不幸的是在 iOS 上不行
    【解决方案2】:

    只需显示一个按钮即可打开手电筒或在 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)
          }**
       );
    

    【讨论】:

    • { ... showTorchButton : false, torchOn: false ...} 如果要打开,请禁用自动手电筒,只需按照蝎子“扫描时,如果要打开 LED 灯,只需增加音量。如果想让 LED 灯熄灭,请降低音量"
    【解决方案3】:

    使用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
           }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多