Deprecation warning

Please note that this is outdated documentation for an older release of the Scandit Barcode Scanner SDK.

We are deprecating the 5.x API on all platforms (except Linux). Release 5.19 in April 2021 will be our final. Applications running 5.x will continue to work, and we will continue to release critical bug fixes and security patches only, for one year. We encourage you to migrate to 6.x and take advantage of our latest / advanced features and improved performance.

You'll find the updated documentation at: Data Capture SDK Documentation for Android

Inherits OnScanListener, and ProcessFrameListener.

Public Member Functions

void setListener (ScanCaseListener listener)
 
void setState (int state)
 
void setScanCaseMode (int scanCaseMode)
 
void setScanCaseMode (int scanCaseMode, Runnable completionCallback)
 
int getState ()
 
RelativeLayout getCameraPreview ()
 
ScanOverlay getCameraPreviewOverlay ()
 
void setVolumeButtonToScanEnabled (boolean enabled)
 
boolean isVolumeButtonToScanEnabled ()
 
void setHardwareButtonToScanEnabled (boolean enabled)
 
boolean isHardwareButtonToScanEnabled ()
 
boolean onKeyDown (int keyCode, KeyEvent event)
 
boolean onKeyUp (int keyCode, KeyEvent event)
 
void applySettings (ScanCaseSettings settings, Runnable completionCallback)
 
void setTimeout (int fromState, final int toState, long timeout)
 
void removeTimeoutFromState (int fromState)
 
void setScanBeepEnabled (boolean enabled)
 
void setErrorSoundEnabled (boolean enabled)
 
void setScanSoundResource (int resId)
 
void setErrorSoundResource (int resId)
 
void didScan (ScanSession session)
 
void didProcess (byte[] imageBuffer, int width, int height, ScanSession session)
 

Static Public Member Functions

static ScanCase acquire (Context context, ScanCaseSettings settings, ScanCaseListener listener)
 

Static Public Attributes

Possible states of the scan case.
static final int STATE_OFF
 
static final int STATE_STANDBY
 
static final int STATE_ACTIVE
 
Possible modes of the scan case.
static final int MODE_FACE_FORWARD
 
static final int MODE_FACE_DOWNWARD
 

Detailed Description

Start a scanner for the Scandit case.

Example (minimal) usage:

// Set your app key on the license first.
ScanditLicense.setAppKey(sScanditSdkAppKey);
// Create the settings used for the scan case.
ScanCaseSettings scanCaseSettings = ScanCaseSettings();
// Enable symbologies etc.
scanCaseSettings.setSymbology(Barcode.SYMBOLOGY_EAN13, true);
// Instantiate the scan case.
ScanCase scanCase = ScanCase.acquire(context, scanSettings, this);
Since
5.6.0

Member Function Documentation

static ScanCase acquire ( Context  context,
ScanCaseSettings  settings,
ScanCaseListener  listener 
)
static

Initializes a new scan case.

Note that the initial invocation of this method will activate the Scandit Barcode Scanner SDK, after which the device will count towards your device limit.

Make sure to set the app key available from your Scandit account through ScanditLicense.setAppKey before you call this initializer.

This is the recommended way to create a new ScanCase object.

Parameters
contextThe context we are operating in.
settingsThe scan settings to use. You may pass null, which is identical to passing a default settings instance constructed through the parameterless constructor.
listenerThe scan case listener.
Returns
The newly constructed scan case instance.
Since
5.6.0
void setListener ( ScanCaseListener  listener)

Returns the listener for this scan case.

See also
ScanCaseListener.didInitializeScanCase is called when the scan case finished the initalization process.
ScanCaseListener.didScan is invoked whenever a new code is scanned.
ScanCaseListener.didChangeState is invoked whenever ScanCase state is changed.
Parameters
listenerThe scan case listener.
Since
5.6.0
void setState ( int  state)

Sets the state of the scan case.

Set the state of the scan case. Possible states: ScanCase.STATE_OFF to stop the scanner (camera off, scanner off, torch off); ScanCase.STATE_STANDBY to pause the scanner in order to save power but be ready to resume scanning (camera on, scanner off, torch off); ScanCase.STATE_ACTIVE to start scanning (camera on, scanner on, torch on).

After the initialization the default state is ScanCase.STATE_STANDBY.

Parameters
stateThe new scan case state.
Since
5.6.0
void setScanCaseMode ( int  scanCaseMode)

Sets the mode of the scan case.

Set the mode of the scan case. Possible modes: ScanCase.MODE_FACE_FORWARD to switch to the forward facing scan; ScanCase.MODE_FACE_DOWNWARD to switch to the downward (regular) facing scan.

After the initialization the default mode is ScanCase.MODE_FACE_FORWARD.

Parameters
scanCaseModeThe new scan case mode.
Since
5.6.0
void setScanCaseMode ( int  scanCaseMode,
Runnable  completionCallback 
)

Sets the mode of the scan case.

Set the mode of the scan case. Possible modes: ScanCase.MODE_FACE_FORWARD to switch to the forward facing scan; ScanCase.MODE_FACE_DOWNWARD to switch to the downward (regular) facing scan.

After the initialization the default mode is ScanCase.MODE_FACE_FORWARD.

Parameters
scanCaseModeThe new scan case mode.
completionCallbackrunnable to be executed when the new mode have been set.
Since
5.6.0
int getState ( )

Gets the state of the scan case.

Get the state of the scan case. Possible states: ScanCase.STATE_OFF to stop the scanner (camera off, scanner off, torch off); ScanCase.STATE_STANDBY to pause the scanner in order to save power but be ready to resume scanning (camera on, scanner off, torch off); ScanCase.STATE_ACTIVE to start scanning (camera on, scanner on, torch on).

After the initialization the default state is ScanCase.STATE_STANDBY.

Returns
Current scan case state.
Since
5.6.0
RelativeLayout getCameraPreview ( )

The camera preview.

Use this getter if you would like to display a camera preview when using the scan case.

Returns
Camera preview.
Since
5.6.0
ScanOverlay getCameraPreviewOverlay ( )

The overlay of the camera preview.

Use this getter if you are displaying the camera preview and would like to adjust the overlay.

Returns
Overlay of the camera preview.
Since
5.7.0
void setVolumeButtonToScanEnabled ( boolean  enabled)

Turn on/off scanning via the volume button.

Set to true to change the state of the scan case using the volume button (holding the volume button changes the state to ScanCase.STATE_ACTIVE, while releasing it changes the state to ScanCase.STATE_STANDBY). Set to false to not control the state of the scan case via the volume button.

The default value is false.

Parameters
enabledBoolean that states if volume buttons should be enabled.
Since
5.6.0
boolean isVolumeButtonToScanEnabled ( )

Scanning via the volume button.

Check if changing the state of the scan case using the volume button is enabled.

The default value is false.

Returns
Boolean that states if volume buttons are enabled.
Since
5.6.0
void setHardwareButtonToScanEnabled ( boolean  enabled)

Turn on/off scanning via the hardware button.

Set to true to change the state of the scan case using the hardware button (holding the hardware button changes the state to ScanCase.STATE_ACTIVE, while releasing it changes the state to ScanCase.STATE_STANDBY). Set to false to not control the state of the scan case via the hardware button.

The default value is false.

Parameters
enabledBoolean that states if hardware button should be enabled.
Since
5.6.0
boolean isHardwareButtonToScanEnabled ( )

Scanning via the hardware button.

Check if changing the state of the scan case using the hardware button is enabled.

The default value is false.

Returns
Boolean that states if hardware button is enabled.
Since
5.6.0
boolean onKeyDown ( int  keyCode,
KeyEvent  event 
)

Physical (volume or hardware) button pressed action.

If the received keyCode represents a volume or hardware button being pressed and the corresponding button is enabled (via ScanCase.setVolumeButtonToScanEnabled(boolean) or ScanCase.setHardwareButtonToScanEnabled(boolean)), this method will set the state of the Case to ScanCase.STATE_ACTIVE.

This method has to be called by the Activity or Service that listens to the Android's key events.

Parameters
keyCodeThe value in event.getKeyCode().
eventDescription of the key event.
Returns
True, if the event is handled. False, if you want to allow the event to be handled by the next receiver.
Since
5.6.0
boolean onKeyUp ( int  keyCode,
KeyEvent  event 
)

Physical (volume or hardware) button released action.

If the received keyCode represents a volume or hardware button being released and the corresponding button is enabled (via ScanCase.setVolumeButtonToScanEnabled(boolean) or ScanCase.setHardwareButtonToScanEnabled(boolean)), this method will set the state of the Case to ScanCase.STATE_STANDBY.

This method has to be called by the Activity or Service that listens to the Android's key events.

Parameters
keyCodeThe value in event.getKeyCode().
eventDescription of the key event.
Returns
True, if the event is handled. False, if you want to allow the event to be handled by the next receiver.
Since
5.6.0
void applySettings ( ScanCaseSettings  settings,
Runnable  completionCallback 
)

Change the scan settings of an existing picker instance.

The scan settings are applied asynchronously after this call returns. You may use the completion handler to get notified when the settings have been applied to the picker. All frames processed after the settings have been applied will use the new scan settings.

Parameters
settingsthe settings to apply.
completionCallbackrunnable to be executed when the new settings have been applied.
Since
5.6.0
void setTimeout ( int  fromState,
final int  toState,
long  timeout 
)

Set a timeout to automatically change state after a specific interval.

Set a timer that is started whenever the state is changed to fromState. The timer will have a time interval equal to timeout and then it will switch the state of the scan case to toState. The timer will be created every time the state of the scan case is equal to fromState. At any given time there could not be more than one timeout for each fromState.

Parameters
timeoutThe interval of the timer, in milliseconds.
fromStateThe state from which the timer should start.
toStateThe new state when the timer is fired.
Since
5.6.0
void removeTimeoutFromState ( int  fromState)

Remove a previously set timeout.

Remove a previously set timeout to avoid starting a new timer when the state is changed to fromState.

Parameters
fromStateThe state from which the timer should start.
Since
5.6.0
void setScanBeepEnabled ( boolean  enabled)

Whether to play a beep sound upon a successful scan.

By default, a beep sound is played upon successfully scanning a barcode. Set this property to false, to disable the sound. If the ringer mode is set to silent, no beep sound is played, regardless of the value of this property.

Parameters
enabledBoolean that states if the beep sound after successful scan should be enabled or not.
Since
5.6.0
void setErrorSoundEnabled ( boolean  enabled)

Whether to play an error sound when no code was scanned.

By default, an error sound is played when activating the scanner using the volume button control when no could be scanned. If the ringer mode is set to silent, no sound is played, regardless of the value of this property.

Parameters
enabledBoolean that states if the error sound should be enabled or not.
Since
5.6.0
void setScanSoundResource ( int  resId)

Sets the audio sound played when a code has been successfully recognized.

The file needs to be included in the application bundle, within /res/raw folder.

The default is: "beep.wav"

Parameters
resIdThe resource id of the sound file.
Since
5.6.0
void setErrorSoundResource ( int  resId)

Sets the audio sound played when no code was recognized.

This sound file is played when controlling the scan case with the volume button and no code was scanned.

The file needs to be included in the application bundle, within /res/raw folder.

The default is: "error.wav"

Parameters
resIdThe resource id of the sound file.
Since
5.6.0
void didScan ( ScanSession  session)

Called whenever a new barcode has been successfully recognized.

Newly recognized codes are available as ScanSession.getNewlyRecognizedCodes(). When didScan callback is invoked, there is always at least one new code available.

The callback is invoked in the thread running the barcode recognition engine. This means, any change to the graphical user interface will have to be moved to the UI thread. Likewise, Since the callback blocks the engine, any expensive calculation should be posted to a Handler.

When no more codes should be scanned, call ScanSession.stopScanning, when the scan session should be paused, call ScanSession.pauseScanning. Calling these two methods is preferred over calling BarcodePicker.stopScanning and BarcodePicker.pauseScanning, as it will immediately stop/pause the scanning.

Note, it is only safe to access the session object inside the didScan callback, but you can safely store the lists of barcodes returned by ScanSession.getAllRecognizedCodes and ScanSession.getNewlyRecognizedCodes

Parameters
sessioncurrent scan session
See also
ScanSettings.setCodeDuplicateFilter
ScanSettings.setCodeCachingDuration

Implements OnScanListener.

void didProcess ( byte[]  imageBuffer,
int  width,
int  height,
ScanSession  session 
)

Invoked every time a frame has been processed by the barcode recognition engine.

In contrast to com.scandit.barcodepicker.OnScanListener.didScan, the didProcess callback is invoked after every frame, regardless whether a code could be successfully decoded or not. If your are only interested in fully decoded codes, use the com.scandit.barcodepicker.OnScanListener instead.

The didProcess callback is invoked in the thread that runs the recognition engine and blocks further processing. In case codes have been recognized in the same frame, the ProcessFrameListener.didProcess callback is invoked after com.scandit.barcodepicker.OnScanListener.didScan.

Parameters
imageBufferthe raw image data that was processed in NV21 format
widthwidth of the image buffer in pixels
heightheight of the image buffer in pixels
sessioncontains information on the current recognition process. It is only valid to access the scan session from within the callback. If part of the information is required outside the callback it must be copied first.
Since
4.9.0

Implements ProcessFrameListener.

Member Data Documentation

final int STATE_OFF
static

Camera is off, torch is off.

final int STATE_STANDBY
static

Camera is on, scanner is off, torch is off.

final int STATE_ACTIVE
static

Camera is on, scanner is on, torch is on.

final int MODE_FACE_FORWARD
static

Forward scanning mode (default).

final int MODE_FACE_DOWNWARD
static

Regular scanning mode, can be used without the case.


The documentation for this class was generated from the following file:
  • ScanCase.java