【问题标题】:phonegap barcodescanner: how to multiple scan at a timephonegap 条码扫描仪:如何一次进行多次扫描
【发布时间】:2014-04-01 09:22:35
【问题描述】:

我正在开发一个带有 phonegap 并针对 android 设备的 sencha 触摸应用程序。在应用程序中,有一个扫描条形码的选项。我使用this link 来实现条码扫描。在这里,用户可以扫描条形码并返回煎茶屏幕。

根据我的要求,该应用应允许用户一次扫描多个条形码,并且应在用户完成扫描后返回屏幕。我期待使用 phonegap 捕获插件的类似方法(允许用户同时拍摄多个图像/视频/声音,结果将在一个数组中)。

有没有办法同时进行多次扫描。

【问题讨论】:

    标签: cordova phonegap-plugins barcode-scanner


    【解决方案1】:

    我刚刚遇到了同样的问题,这是我想出的解决方法。

    简而言之:每当成功返回代码时,我将扫描的信息保存到数组中,然后立即重新开始扫描。

    这是我用来在一个简单的流星应用程序中测试我的解决方法的代码:

      // list to collect successfully scans
      var scanned_list=[];
    
      // callback function that will be executed everytime barcodescanner.scan ends without error
      scannedOneItem = function (result) {
    
        // user cancelled the scan: now check if we have something scanned already or not:
        if(result.cancelled){
          if(scanned_list.length>0){
            // no items scanned, user cancelled
            alert("Scanned items: " + scanned_list.length);
          }
          else{
            alert("Scanned canceled");
          }
        }
        // a item was scanned successfully - add it to list, and restart barcodescanner
        else{
          scanned_list.append(result.text);
          cordova.plugins.barcodeScanner.scan(
              scannedOneItem,
              function (error) {
                alert("Scanning failed: " + error);
              }
          );
        }
      }
      Template.barcode_scanner.events({
        'click button': function () {
          // start scanning when button is pressed:
          cordova.plugins.barcodeScanner.scan(
              scannedOneItem,
              function (error) {
                alert("Scanning failed: " + error);
              }
          );
        }
      });
    

    【讨论】:

    • 这不起作用。扫描仪永远不会重新启动,它只会在扫描一个项目后关闭。我在这个答案中复制并测试了完全相同的代码。
    • 我现在没有任何项目可以对此进行测试。您是否对其进行了任何调试,为什么它对您来说失败了?第一次扫描成功?它比条形码扫描仪给你一个错误吗?如果第一次扫描成功,则应明确尝试再次打开条形码扫描仪。如果它不这样做,它看起来像条码扫描仪中的某些东西发生了变化......
    【解决方案2】:

    该插件目前不支持此功能。您必须联系插件的作者进行修改或自己进行修改。

    【讨论】:

      【解决方案3】:

      它已经使用上述@80prozet 解决方案,您必须考虑使用本机后退按钮取消扫描:

      async scan_products (){
          const results           = await this.barcode.scan();
      
          if(results.cancelled) {
              this.platform.ready().then(() => {
                  // catch the native back button to cancel scan
                  this.platform.registerBackButtonAction(function(event){
                      event.preventDefault();
                      event.stopPropagation();
      
                      console.log("Scanned Canceled");
                  });
              });
          }
          // a item was scanned successfully - add it to list, and restart barcodescanner //
          else{
              this.scanned_products.push(results.text);
              this.scan_products();
          }
      
      
          console.log(results);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多