【发布时间】:2019-03-01 14:50:07
【问题描述】:
如何将 phonegap 条形码扫描仪插件与 cordova-plugin-camera-preview 一起使用,这样当我在我的 Angular 应用程序中单击扫描按钮时,相机会在我的应用程序中预览并扫描条形码并给我结果
【问题讨论】:
-
请包含一些您已经尝试过的代码示例。
标签: angular cordova camera barcode-scanner
如何将 phonegap 条形码扫描仪插件与 cordova-plugin-camera-preview 一起使用,这样当我在我的 Angular 应用程序中单击扫描按钮时,相机会在我的应用程序中预览并扫描条形码并给我结果
【问题讨论】:
标签: angular cordova camera barcode-scanner
你让自己变得复杂
条码扫描插件
上面提到的条形码扫描仪已经可以访问相机,您不必使用其他插件,例如您提到的用于 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);
【讨论】: