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

BarcodePickerActivity Class Reference

Inherits Activity, and OnScanListener.

Inherited by BarcodePickerExternalActivity.

Public Member Functions

void didScan (ScanSession session)

Protected Member Functions

ScanSettings settingsFromIntent (Intent intent)
void setupScanUIFromIntent (BarcodePicker picker, Intent intent)
void buildSuccessResult (Intent resultIntent, ScanSession session)
void buildCancelResult (Intent resultIntent)

Detailed Description

Barcode Picker Activity that can be configured through an intent.

The BarcodePickerActivity provides an easy-to use solution for full-screen barcode scanning. The scanned barcode (symbology, encoded data) is returned as part of the activity result.

Sample Usage

The following code shows how to start the BarcodePickerActivity to scan a retail code (UPCA, EAN13, EAN8, UPCE):

// set Scandit BarcodeScanner app key before starting the activity.
Intent launchIntent = new Intent(MyActivity.this, BarcodePickerActivity.class);
launchIntent.putExtra("appKey", "Your Scandit BarcodeScanner App Key Goes Here");
launchIntent.putExtra("enabledSymbologies", new int[] {
// start activity and listen for result.
startActivityForResult(launchIntent, 42);

To get the scanned barcode, you need to override your activity's onActivityResult handler.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != 42) return;
String message = "no code recognized";
if (data.getBooleanExtra("barcodeRecognized", false)) {
message = String.format("%s (%s)", data.getStringExtra("barcodeData"),
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();

Scanner Configuration

The barcode scanning process can be configured through the following extras attached to the intent:

  • enabledSymbologies: Array of symbologies to enable. The values correspond to the symbology values defined in Barcode. For example, EAN13 and UPCA decoding can be enabled as follows:
    intent.putExtra("enabledSymbologies", new int[] { Barcode.SYMBOLOGY_EAN13, Barcode.SYMBOLOGY_UPCA });
  • cameraFacingPreference: Indicates whether the front or back-facing camera should be preferred. Must be one of ScanSettings.CAMERA_FACING_FRONT or ScanSettings.CAMERA_FACING_BACK. When this value is not present, the back-facing camera is preferred.
  • showTorchButton: Boolean indicating whether the torch button should be shown in the scan UI. When the value is not present, the torch button is not shown.
  • cameraSwitchVisibility: Influences the visibility of the camera switch button. shown in the UI. Must be one of ScanOverlay.CAMERA_SWITCH_NEVER, ScanOverlay.CAMERA_SWITCH_ON_TABLET, ScanOverlay.CAMERA_SWITCH_ALWAYS. By default, the camera switch visibility is ScanOverlay.CAMERA_SWITCH_NEVER.
  • guiStyle: Lets you choose the style of the scan UI. Can either be ScanOverlay.GUI_STYLE_DEFAULT or ScanOverlay.GUI_STYLE_LASER. When the value is not present, ScanOverlay.GUI_STYLE_DEFAULT is assumed.
  • restrictScanningArea: Boolean indicating whether the scanning area should be restricted or not. By default, codes are searched in the full image. Use this option to only scan codes in the center of the image.
  • scanningAreaHeight: Floating point value that specifies the height of the scanning area. When using this option, you must also set restrictScanningArea to true.

Scanner Result

The result of the barcode scanner is attached to the Activity result as extras. The following extras are defined:

  • barcodeRecognized: Boolean that indicates whether a barcode was recognized. This value is set to false when the activity returns when the user presses the back button.
  • barcodeData: The data string contained in the scanned barcode. Only exists when barcodeRecognized is set to true.
  • barcodeRawData: The raw data contained in the scanned barcode as a byte array. Only exists when barcodeRecognized is set to true.
  • barcodeSymbology: The barcode symbology of the recognized code. Only exists when barcodeRecognized is set to true.
  • barcodeSymbologyName: The barcode symbology name. Only exists when barcodeRecognized is set to true.

Member Function Documentation

ScanSettings settingsFromIntent ( Intent  intent)

Creates a new scan settings instance to configure the barcode picker.

You may override this method to further customize the scan settings to meet your specific use-case.

intentthe intent used to start this activity.
void setupScanUIFromIntent ( BarcodePicker  picker,
Intent  intent 

Uses the configuration options in the intent to setup the scan UI.

You can override this method to further customize the scan UI.

pickerthe picker to configure.
intentthe intent used to launch the activity.
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

sessioncurrent scan session
See also

Implements OnScanListener.

void buildSuccessResult ( Intent  resultIntent,
ScanSession  session 

Builds the intent result in case of a successful scan.

You can override this method to customize the intent the activity returns. This function is not called on the main thread, UI operations can therefore not be performed.

resultIntentThe intent which will be returned as the result.
sessionThe scan session of the successful scan.
void buildCancelResult ( Intent  resultIntent)

Builds the intent result in case of the user canceling the activity.

You can override this method to customize the intent the activity returns.

resultIntentThe intent which will be returned as the result.

The documentation for this class was generated from the following file: