Data Capture Context
Defined in package com.scandit.datacapture.core.capture
- DataCaptureContext
class DataCaptureContextAdded 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 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.
A 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, MatrixScan Get Started, Core Concepts <https://docs.scandit.com/core-concepts>.
- forLicenseKey(licenseKey)
fun DataCaptureContext.forLicenseKey(licenseKey: String): DataCaptureContext
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. For this reason, it’s recommended to use the singleton context available through the static sharedInstance property.
- builder(licenseKey)
fun DataCaptureContext.builder(licenseKey: String): DataCaptureContextBuilder
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.
Note
It’s recommended to initialize the singleton context through the static initialize() method, unless several contexts are specifically needed.
- DEVICE_ID
val DataCaptureContext.DEVICE_ID: String
Added in version 6.4.0
The unique identifier of the device as used by the Scandit Data Capture SDK. This identifier does not contain any device identifying information that would be usable outside of the context of the Scandit Data Capture SDK itself.
- openSourceSoftwareLicenseInfo
val DataCaptureContext.openSourceSoftwareLicenseInfo: OpenSourceSoftwareLicenseInfo
Added in version 7.0.0
The license text and attributions for all third party software used by the Scandit SDK.
val DataCaptureContext.sharedInstance: DataCaptureContext
Added in version 7.1.0
Holds the singleton instance of DataCaptureContext, which is managed by Scandit Data Capture SDK. This instance is unusable until properly configured.
To configure the instance, call initialize().
- setFrameSource(frameSource, whenDone)
fun setFrameSource(frameSource: FrameSource?, whenDone: Runnable?)
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)
fun setFrameSource(frameSource: FrameSource?)
Added in version 6.0.0
Same as setFrameSource() with the second argument set to null.
- frameSource
val frameSource: FrameSource?
Added in version 6.0.0
Readonly attribute to get the current frame source. To change the frame source use setFrameSource().
- addListener(listener)
fun addListener(listener: DataCaptureContextListener)
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)
fun removeListener(listener: DataCaptureContextListener)
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)
fun addFrameListener(listener: DataCaptureContextFrameListener)
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)
fun removeFrameListener(listener: DataCaptureContextFrameListener)
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)
fun addMode(mode: DataCaptureMode)
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.
A data capture context can only be associated with one mode at a time. If multiple modes are associated with the same context, the context will not process any frames and report an error.
Note
If you’re using androidx.fragments dependency and have the situation where a scanning fragment navigates to another scanning fragment with an incompatible mode, make sure you’re using version 1.3.0+ of the dependency. If not, you may run into an incompatible modes error, as the new fragment gets resumed before the previous is paused and for some time incompatible modes may be enabled in the DataCaptureContext at the same time. This results in sessions being empty of any result.
- setMode(mode)
fun setMode(mode: DataCaptureMode)
Added in version 7.1.0
Sets the specified data capture mode as the active mode of 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.
A data capture context can only be associated with one mode at a time. If a new mode is associated with the context, the previous mode will be replaced by the new one.
Note
If you’re using androidx.fragments dependency and have the situation where a scanning fragment navigates to another scanning fragment with an incompatible mode, make sure you’re using version 1.3.0+ of the dependency. If not, you may run into an incompatible modes error, as the new fragment gets resumed before the previous is paused and for some time incompatible modes may be enabled in the DataCaptureContext at the same time. This results in sessions being empty of any result.
- removeMode(mode)
fun removeMode(mode: DataCaptureMode)
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.
- removeCurrentMode()
fun removeCurrentMode()Added in version 7.1.0
Removes the currently active mode from this capture context. If the context has no capture mode associated to it, this call has no effect.
- removeAllModes()
fun removeAllModes()Added in version 6.2.0
Removes all modes from this capture context. If there currently are no captures modes associated to the context, this call has no effect.
- licenseInfo
val licenseInfo: LicenseInfo?
Added in version 6.4.0
Information about the license the context was created for.
Note
This value is available with a small delay. To make sure it is available, set a listener and as soon as DataCaptureContextListener.onObservationStarted() was called, it is available.
- release()
fun 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 until a call to initialize() is made, 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.
- applySettings(settings)
fun applySettings(settings: DataCaptureContextSettings)
Added in version 6.4.0
Applies the given settings to the data capture context.
- initialize(licenseKey)
fun DataCaptureContext.initialize(licenseKey: String): DataCaptureContext
Added in version 7.1.0
Initializes the singleton context instance with the provided license key, and returns the same instance.
- initialize(licenseKey, frameworkName, frameworkVersion, deviceName, externalId, settings)
fun DataCaptureContext.initialize(licenseKey: String, frameworkName: String?, frameworkVersion: String?, deviceName: String?, externalId: String?, settings: DataCaptureContextSettings): DataCaptureContext
Added in version 7.1.0
Initializes the singleton context instance with the provided arguments, and returns the same instance.