Barcode Capture Listener

Defined in library scandit_datacapture_barcode

BarcodeCaptureListener
abstract class BarcodeCaptureListener

Added in version 6.7.0

Listener interface for traditional barcode capture.

didScan(barcodeCapture, session)
void didScan(BarcodeCapture barcodeCapture,
        BarcodeCaptureSession session)

Added in version 6.7.0

Invoked whenever a code has been scanned. The newly scanned codes can be retrieved from BarcodeCaptureSession.newlyRecognizedBarcodes.

This callback will be blocking the further processing of frames, so you should return from it as quickly as possible. Therefore, if you need to perform a time-consuming operation, like querying a database or opening an URL encoded in the barcode data, consider moving it out of this callback, e.g. by using a timeout to let this function return before you do any more work. It is advised to disable the capture mode while you’re doing additional work and enabling it again once that work is done.

Sometimes, after receiving this callback, you may want to pause scanning or to stop scanning completely.

  • To pause scanning, but keep the camera (frame source) running, just set the barcode capture’s enabled property to false.

captureMode.isEnabled = false;

While it’s possible to only stop the camera and keep the capture mode enabled, this may lead to additional scan events being delivered, which is typically not desired. The following lines of code show how to disable the capture mode and stop the frame source as well:

// no more didScan callbacks will be invoked after this call.
captureMode.isEnabled = false;
// asynchronously turn off the camera
captureMode.context.frameSource.switchToDesiredState(FrameSourceState.off);
didUpdateSession(barcodeCapture, session)
void didUpdateSession(BarcodeCapture barcodeCapture,
        BarcodeCaptureSession session)

Added in version 6.7.0

Invoked after a frame has been processed by barcode capture and the session has been updated. In contrast to didScan(), this method is invoked, regardless whether a code was scanned or not. If codes were recognized in this frame, this method is invoked after didScan().

This callback will be blocking the further processing of frames, so you should return from it as quickly as possible. Therefore, if you need to perform a time-consuming operation, like querying a database or opening an URL encoded in the barcode data, consider moving it out of this callback, e.g. by using a timeout to let this function return before you do any more work. It is advised to disable the capture mode while you’re doing additional work and enabling it again once that work is done.

See the documentation in didScan() for information on how to properly stop recognition of barcodes.

Barcode Capture Advanced Listener

Defined in library scandit_datacapture_barcode

BarcodeCaptureAdvancedListener
abstract class BarcodeCaptureAdvancedListener

Added in version 6.14.0

Listener interface for traditional barcode capture.

didScan(barcodeCapture, session, getFrameData)
void didScan(BarcodeCapture barcodeCapture,
        BarcodeCaptureSession session,
        Future<FrameData> getFrameData())

Added in version 6.14.0

Invoked whenever a code has been scanned. The newly scanned codes can be retrieved from BarcodeCaptureSession.newlyRecognizedBarcodes.

This callback will be blocking the further processing of frames, so you should return from it as quickly as possible. Therefore, if you need to perform a time-consuming operation, like querying a database or opening an URL encoded in the barcode data, consider moving it out of this callback, e.g. by using a timeout to let this function return before you do any more work. It is advised to disable the capture mode while you’re doing additional work and enabling it again once that work is done.

Sometimes, after receiving this callback, you may want to pause scanning or to stop scanning completely.

  • To pause scanning, but keep the camera (frame source) running, just set the barcode capture’s enabled property to false.

    captureMode.isEnabled = false;
    
  • To stop scanning, you will need to both disable the capture mode and stop the frame source. While it’s possible to only stop the camera and keep the capture mode enabled, this may lead to additional scan events being delivered, which is typically not desired. The following lines of code show how to disable the capture mode and stop the frame source as well:

    // no more didScan callbacks will be invoked after this call.
    captureMode.isEnabled = false;
    // asynchronously turn off the camera
    captureMode.context.frameSource.switchToDesiredState(FrameSourceState.off);
    
didUpdateSession(barcodeCapture, session, getFrameData)
void didUpdateSession(BarcodeCapture barcodeCapture,
        BarcodeCaptureSession session,
        Future<FrameData> getFrameData())

Added in version 6.14.0

Invoked after a frame has been processed by barcode capture and the session has been updated. In contrast to didScan(), this method is invoked, regardless whether a code was scanned or not. If codes were recognized in this frame, this method is invoked after didScan().

This callback will be blocking the further processing of frames, so you should return from it as quickly as possible. Therefore, if you need to perform a time-consuming operation, like querying a database or opening an URL encoded in the barcode data, consider moving it out of this callback, e.g. by using a timeout to let this function return before you do any more work. It is advised to disable the capture mode while you’re doing additional work and enabling it again once that work is done.

See the documentation in didScan() for information on how to properly stop recognition of barcodes.