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 Xamarin.Android and Data Capture SDK Documentation for Xamarin.iOS

Using the Scandit Scan Case in your app

This guide show how to scan barcodes with the Scandit scan case using the ScanCase API.

Using the ScanCase API is relatively easy: all you need to do is to create an ScanCase object and subclass the ScanCaseDelegate.

Creating an instance of ScanCase

In order to create an instance of ScanCase, you first need to set the app key (if you haven't already), create a ScanCaseSettings, and enable the symbologies you need. At this point you can create a ScanCase.

var settings = new ScanCaseSettings();
settings.SetSymbologyEnabled(Symbology.EAN13, true);
settings.SetSymbologyEnabled(Symbology.UPC12, true);
_delegate = new MyScanCaseDelegate();
_scanCase = ScanCase.Acquire(settings, _delegate);

Scanning with ScanCase is driven by it's state property. ScanCase initially starts in ScanCaseState.Standby and can be set to one of the following three states:

  • ScanCaseState.Off: camera is off, torch is off.
  • ScanCaseState.Standby: camera is on but with throttled frame-rate, scanner is off, torch is off.
  • ScanCaseState.Active: camera is on, scanner is on, torch is on.

In order to start scanning, you just need to change the state to ScanCaseState.Active:

_scanCase.State = ScanCaseState.Active;

Implementing the ScanCaseDelegate methods

ScanCaseDelegate consists of three methods. Please note that all these methods are called from a private queue, so you are responsible to switch to the main thread if needed. Let's check them one by one.

The first method is called when ScanCase finished the initialization process and it's ready to be used.

public override void DidInitialize(ScanCase scanCase)
// ScanCase is ready, and the state is ScanCaseState.Standby

Whenever a new code is scanned the following method is called. If you want to keep scanning new codes, return ScanCaseState.Active, if you want to temporary pause the scanner return ScanCaseState.Standby. You can also return ScanCaseState.Off if you don't plan to scan new codes relatively soon.

Please note that changing from ScanCaseState.Off to ScanCaseState.Active takes more time than switching from ScanCaseState.Standby to ScanCaseState.Active.

public override ScanCaseState DidScan(ScanCase scanCase, ScanCaseSession session)
// switch to the main thread if you need to (like for interacting with UIKit)
// ...
return ScanCaseState.Standby;

Whenever the state of ScanCase changes the following method is called. There are multiple reasons for which the state can be changed:

  • ScanCaseStateChangeReason.Manual: the state has been changed programmatically by changing the ScanCase.State property or by returning a different state from the ScanCaseDelegate.DidScan() delegate method.
  • ScanCaseStateChangeReason.Timeout: the state has been changed because of a timeout (check the timeout section).
  • ScanCaseStateChangeReason.VolumeButton: the state has been changed by the volume button (check the volume button section).
public override void DidChangeState(ScanCase scanCase, ScanCaseState newState, ScanCaseStateChangeReason reason)

Enabling the volume button to start scanning

It is possible to use the volume button to scan. Keeping the volume button pressed will keep the scan case in ScanCaseState.Active state, while releasing the button will change the state to ScanCaseState.Standby. To enable this feature, all you need to do is:

_scanCase.VolumeButtonToScanEnabled = true;

You know when the state changes, because of the volume button, in ScanCaseDelegate.DidChangeState(), the reason will be ScanCaseStateChangeReason.VolumeButton.

Using timeouts to switch state

It is possible to switch from one state to another one automatically after a specific timeout. This could be useful, for instance, to switch the scanner off after a long time of inactivity in order to save power.

The following code changes the state from ScanCaseState.Standby to ScanCaseState.Off after approximately 60 seconds.

_scanCase.SetTimeout(60, 5, ScanCaseState.Standby, ScanCaseState.Off);

You know when the state changes because of a timeout in ScanCaseDelegate.DidChangeState(), the reason will be ScanCaseStateChangeReason.Timeout.