条码扫描器以及cordova相机预览

时间:2019-03-01 14:50:07

标签: angular cordova camera barcode-scanner

如何将phonegap条形码扫描仪插件与cordova-plugin-camera-preview一起使用,以便当我单击我的角度应用程序中的扫描按钮时,摄像头会在我的应用程序内预览并扫描条形码并提供结果

1 个答案:

答案 0 :(得分:0)

您让自己变得复杂

条形码扫描器插件

  

https://github.com/phonegap/phonegap-plugin-barcodescanner

上面提到的条形码扫描仪已经可以访问相机,而您不必使用其他插件,例如您提到的cordova相机预览插件。

示例:

//plugin options
var options= {
      preferFrontCamera : true, // iOS and Android
      showFlipCameraButton : true, // iOS and Android
      showTorchButton : true, // iOS and Android
      torchOn: true, // Android, launch with the torch switched on (if available)
      saveHistory: true, // Android, save scan history (default false)
      prompt : "Place a barcode inside the scan area", // Android
      resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
      formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
      orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
      disableAnimations : true, // iOS
      disableSuccessBeep: false // iOS and Android
  }

 //success callback
function onSuccess(result) {
      alert("We got a barcode\n" +
            "Result: " + result.text + "\n" +
            "Format: " + result.format + "\n" +
            "Cancelled: " + result.cancelled);
 }

//error callback
function onError(error) {
      alert("Scanning failed: " + error);
}

cordova.plugins.barcodeScanner.scan(onSuccess, onError, options);