Data Capture Context#

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

DataCaptureContext#
class DataCaptureContext

Added in version 6.0.0

Data capture context is the main class for running data-capture related tasks. The context manages one or more capture modes, such as BarcodeCapture, or LabelCapture that perform the recognition. The context itself acts as a scheduler, but does not provide any interfaces for configuring data capture capabilities. Configuration and result handling is handled by the data capture modes directly.

Each data capture context has exactly one frame source (typically a built-in camera). The frame source delivers the frames on which the capture modes should perform recognition on. When a new capture context is created, it’s frame source is null and must be initialized for recognition to work.

Typically a DataCaptureView is used to visualize the ongoing data capture process on screen together with one or more overlays. However it’s also possible to use the data capture context without a view to perform off-screen processing.

Related topics: Get Started With Barcode Scanning, Get Started With MatrixScan, Core Concepts of the Scandit Data Capture SDK.

forLicenseKey(licenseKey)#
static @NonNull DataCaptureContext forLicenseKey(@NonNull String licenseKey)

Added in version 6.0.0

Constructs a data capture context with the provided license key.

To set additional properties like a device name or external id, use builder().

Note

Due to resource constraints, only one data capture context instance can be used at a given point in time. Each call to forLicenseKey() disposes previously created data capture contexts, as if release() were called. Disposed contexts cannot be used for recognition anymore.

forLicenseKey(licenseKey, deviceName)#
static @NonNull DataCaptureContext forLicenseKey(@NonNull String licenseKey,
        @NonNull String deviceName)

Added in version 6.0.0

Constructs a data capture context with the provided license key and an optional device name.

The device name allows to optionally identify the device with a user-provided name. This name is then associated with the unique identifier of the device and displayed in the online dashboard.

See forLicenseKey() for details about the context instantiation.

Deprecated since version 6.1.0: Replaced by builder() to set the device name and additional properties.

builder(licenseKey)#
static @NonNull DataCaptureContextBuilder builder(@NonNull String licenseKey)

Added in version 6.1.0

Constructs a data capture context builder to build a data capture context with additional properties such as device name and external ID.

setFrameSource(frameSource, whenDone)#
void setFrameSource(@Nullable FrameSource frameSource, @Nullable Runnable whenDone)

Added in version 6.0.0

Set the frame source of this data capture context.

Frame sources produce frames to be processed by the data capture context. The user typically doesn’t create their own frame sources, but use one of the frame sources provided by the Scandit Data Capture SDK. Typical frame sources are web cams, or built-in cameras of a mobile device.

Setting the frame source to null will effectively stop recognition of this capture context.

When the frame source changes, DataCaptureContextListener.onFrameSourceChanged() will be invoked on all registered listeners.

setFrameSource(frameSource)#
void setFrameSource(@Nullable FrameSource frameSource)

Added in version 6.0.0

Same as setFrameSource() with the second argument set to null.

frameSource#
@Nullable FrameSource getFrameSource()

Added in version 6.0.0

Readonly attribute to get the current frame source. To change the frame source use setFrameSource().

addListener(listener)#
void addListener(@Nullable DataCaptureContextListener listener)

Added in version 6.0.0

Adds the listener to this data capture context. Context listeners receive events when new data capture modes are added, or the frame source changes.

In case the same listener is already observing this instance, calling this method will not add the listener again.

removeListener(listener)#
void removeListener(@Nullable DataCaptureContextListener listener)

Added in version 6.0.0

Removes a previously added listener from this data capture context.

In case the listener is not currently observing this instance, calling this method has no effect.

addFrameListener(listener)#
void addFrameListener(@Nullable DataCaptureContextFrameListener listener)

Added in version 6.0.0

Adds the frame listener to this data capture context. Frame listeners receive events when frames are about to be processed or have been processed by the data capture context.

In case the same listener is already observing this instance, calling this method will not add the listener again.

removeFrameListener(listener)#
void removeFrameListener(@Nullable DataCaptureContextFrameListener listener)

Added in version 6.0.0

Removes a previously added frame listener from this data capture context.

In case the listener is not currently observing this instance, calling this method has no effect.

addMode(mode)#
void addMode(@NonNull DataCaptureMode mode)

Added in version 6.0.0

Adds the specified data capture mode to this capture context. Please note that it is not possible to add a mode associated with a context to a different context. If the mode is already associated with this context, this call has no effect.

Multiple data capture modes can be associated with the same context. However, there are restrictions on which data capture modes can be used together. These restrictions are expressed in terms of capabilities that the capture modes require, .e.g. barcode scanning, tracking. No two capture modes that require the same capabilities can be used with the same data capture context. When conflicting requirements are detected, the data capture context will not process any frames and report an error.

removeMode(mode)#
void removeMode(@NonNull DataCaptureMode mode)

Added in version 6.0.0

Removes the mode from this capture context. If the capture mode is currently not associated to the context, this call has no effect.

release()#
void release()

Added in version 6.0.0

Disposes/releases this data capture context. This frees most associated resources and can be used to save some memory. Disposed/released contexts cannot be used for recognition anymore, trying will result in a ContextStatus with error code 1025. Data capture modes and listeners remain untouched.

This method may be called multiple times on the same context. Further calls have no effect.