Getnet DocsGetnet Docs

Scanning Barcodes

This guide explains how to trigger the professional hardware scanner (laser/imager) on compatible terminals to read barcodes.

This functionality is specific to devices with built-in professional scanning hardware. It does not utilize the device’s standard camera.

Initiating a Scan

To start the scanning process, call the barcodeRead method. This activates the hardware scanner and waits for a barcode to be detected.

manager.barcodeRead(new BarcodeCallback() {
    @Override
    public void onSuccess(BarcodeResponse barcodeResponse) {
        // Handle successful scan
        String codeData = barcodeResponse.getData(); // Hypothetical getter based on typical response objects
        Log.d("Scanner", "Barcode detected: " + codeData);
    }

    @Override
    public void onError(int errorCode) {
        // Handle scanning errors
        handleScanError(errorCode);
    }
});

Handling Errors

The onError callback provides an integer code indicating why the scan failed.

Error CodeMeaningDescription
1TimeoutThe scanner timed out before a barcode was read.
2Not SupportedThe device does not support professional barcode reading.
3CancelledThe user cancelled the scan (e.g., via a physical scan button).
99IndeterminateAn unknown error occurred.

Example Error Handler

private void handleScanError(int errorCode) {
    switch (errorCode) {
        case 1:
            showToast("Scan timed out. Please try again.");
            break;
        case 2:
            showToast("Scanner hardware not available on this device.");
            break;
        case 3:
            showToast("Scan cancelled by user.");
            break;
        default:
            showToast("Unknown scanner error: " + errorCode);
            break;
    }
}