Skip to content

Scan

Supports both single scan and continuous scan modes.

Parameters

PropertyTypeDefault ValueRequiredDescription
modeInt-YesScan mode: 1 for single scan, 2 for continuous scan
desiredFormatsStringnullNoSupported barcode formats. Pass null or leave it empty to support all formats
promptStringNoText prompt displayed on the scan interface.
cameraIdInt0NoCamera ID, 0 for rear camera, 1 for front camera
beepEnabledBooleanfalseNoEnables scanning sound
timeoutInt5000NoTimeout duration for single scan (in milliseconds)
barcodeImageEnabledBooleanfalseNoEnables barcode image generation
xInt0Nox-coordinate for the scan interface display
yInt0Noy-coordinate for the scan interface display
widthInt0NoWidth of the scan interface
heightInt0NoHeight of the scan interface

Example

Single Scan

javascript
 window.BarcodeScanner.scan( {
        mode: 1,
        desiredFormats: "QR_CODE,UPC_A,UPC_E,EAN_8,EAN_13", 
        prompt: "请将条形码置于取景框内扫描", 
        cameraId: 0, 
        beepEnabled: true, 
        timeout: 10000, 
        barcodeImageEnabled: true 
    },
    function (response) {
        alert(JSON.stringify(response));
    },
    function (error) {
        alert(JSON.stringify(error));
    }
);

Continuous scan

javascript
 window.BarcodeScanner.scan({
        mode: 2,
        desiredFormats: "CODE_128",
        prompt: "请将条形码置于取景框内扫描", 
        cameraId: 0, 
        beepEnabled: true,
        y: 0,
        height: 300
    },
    function (response) {
        console.log(JSON.stringify(response));
    },
    function (error) {
        alert(JSON.stringify(error));
    }
);

Apache 2.0 License.