Barcode Capture Listener

Defined in package com.scandit.datacapture.barcode.capture

BarcodeCaptureListener
interface BarcodeCaptureListener

Added in version 6.0.0

Listener interface for traditional barcode capture.

onObservationStarted(barcodeCapture)
void onObservationStarted(@NonNull BarcodeCapture barcodeCapture)

Added in version 6.0.0

Called when the listener starts observing the barcode capture instance.

onObservationStopped(barcodeCapture)
void onObservationStopped(@NonNull BarcodeCapture barcodeCapture)

Added in version 6.0.0

Called when the listener stops observing the barcode capture instance.

onBarcodeScanned(barcodeCapture, session, data)
void onBarcodeScanned(@NonNull BarcodeCapture barcodeCapture,
        @NonNull BarcodeCaptureSession session,
        FrameData data)

Added in version 6.0.0

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

This method is invoked from a recognition internal thread. To perform UI work, you must dispatch to the main thread first. After receiving this callback, you will typically want to start processing the scanned barcodes. Keep in mind however, that any further recognition is blocked until this method completes. Therefore, if you need to perform a time-consuming operation, like querying a database or opening an URL encoded in the barcode data, consider switching to another thread.

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.setEnabled(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.setEnabled(false);
// asynchronously turn off the camera
captureMode.getDataCaptureContext().getFrameSource().switchToDesiredState(FrameSourceState.OFF, null);
onSessionUpdated(barcodeCapture, session, data)
void onSessionUpdated(@NonNull BarcodeCapture barcodeCapture,
        @NonNull BarcodeCaptureSession session,
        FrameData data)

Added in version 6.0.0

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

This method is invoked from a recognition internal thread. To perform UI work, you must dispatch to the main thread first. Further recognition is blocked until this method completes. It is thus recommended to do as little work as possible in this method.

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

Barcode Capture Advanced Listener

Defined in package com.scandit.datacapture.barcode