Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class CodeScannerOptions

  1. Object
  2. CodeScannerOptions

Configuration for CodeScanner.scan(CodeScannerOptions). Every setting has a working default, so an application usually changes only the wording and the accepted symbologies.

CodeScanner.scan(new CodeScannerOptions()
        .title("Scan the ticket")
        .hint("Hold the QR code inside the frame")
        .formats(BarcodeFormat.QR_CODE, BarcodeFormat.AZTEC))
    .ready(code -> {
        if (code == null) {
            return;              // the user pressed back
        }
        admit(code.getValue());
    })
    .except(error -> Log.e(error));

Constructors

public CodeScannerOptions()

Methods

public CodeScannerOptions title(String value)Sets the scanner form’s title.
public CodeScannerOptions hint(String value)Sets the instruction shown below the preview.
public CodeScannerOptions formats(String... values)Restricts which symbologies are accepted, using the BarcodeFormat constants.
public CodeScannerOptions facing(CameraFacing value)Selects which camera the scanner opens.
public CodeScannerOptions torchButton(boolean value)Whether to offer a torch toggle.
public CodeScannerOptions strict(boolean value)Accepts a code only when two frames read it identically.
public CodeScannerOptions visionOptions(VisionOptions value)Passes analyzer options through to the underlying BarcodeScanner, which is how an iOS build selects VisionBackends.mlKitBarcodeScanning() instead of Apple Vision.
public String getTitle()
public String getHint()
public String[] getFormats()
public CameraFacing getFacing()
public boolean isTorchButton()
public boolean isStrict()
public VisionOptions getVisionOptions()The options a BarcodeScanner needs to scan the way these options describe: a copy of the ones passed to visionOptions(VisionOptions) (or the defaults), plus the accepted formats(String...) unless those options name formats of their own, plus strict(boolean) when it was called.

Inherited methods

Constructor details

CodeScannerOptions

public CodeScannerOptions()

Method details

title

public CodeScannerOptions title(String value)
Sets the scanner form’s title.

Parameters

value String
the title, or null for no title

Returns

this options object

hint

public CodeScannerOptions hint(String value)
Sets the instruction shown below the preview.

Parameters

value String
the instruction, or null to show none

Returns

this options object

formats

public CodeScannerOptions formats(String... values)

Restricts which symbologies are accepted, using the BarcodeFormat constants. A code in any other format is ignored and scanning continues, which is what an application that expects a specific kind of code wants: a stray product barcode in the frame does not end the scan. The default accepts every format the backend decodes.

This filters results rather than configuring the detector, so it does not make scanning faster.

Parameters

values String...
accepted format constants; empty or null accepts every format

Returns

this options object

facing

public CodeScannerOptions facing(CameraFacing value)
Selects which camera the scanner opens.

Parameters

value CameraFacing
the camera to use, or null for the back camera

Returns

this options object

torchButton

public CodeScannerOptions torchButton(boolean value)
Whether to offer a torch toggle. The button appears only when the open camera actually has a flash, so leaving this enabled is safe. The default is true.

Parameters

value boolean
whether the toggle may be shown

Returns

this options object

strict

public CodeScannerOptions strict(boolean value)

Accepts a code only when two frames read it identically. By default this applies to PDF417 codes alone; true extends it to every symbology and false turns it off for PDF417 too.

Turn this on for codes printed with little or no error correction, such as a PDF417 at level 0; see VisionOptions.strictBarcodes(boolean), which this sets on the scanner’s detector, for why and how frames are compared. It also reaches a BarcodeScanner built from getVisionOptions(), and overrides a strictBarcodes set on the options passed to visionOptions(VisionOptions).

Parameters

value boolean
whether two matching reads are required

Returns

this options object

visionOptions

public CodeScannerOptions visionOptions(VisionOptions value)
Passes analyzer options through to the underlying BarcodeScanner, which is how an iOS build selects VisionBackends.mlKitBarcodeScanning() instead of Apple Vision.

Parameters

value VisionOptions
analyzer configuration, or null for the defaults

Returns

this options object

getTitle

public String getTitle()

Returns

the scanner form’s title, possibly null

getHint

public String getHint()

Returns

the instruction shown below the preview, possibly null

getFormats

public String[] getFormats()

Returns

defensive copy of the accepted formats; empty accepts all

getFacing

public CameraFacing getFacing()

Returns

the camera the scanner opens

isTorchButton

public boolean isTorchButton()

Returns

whether a torch toggle may be shown

isStrict

public boolean isStrict()

Returns

whether every code must be read identically twice before it is accepted (PDF417 is by default either way)

getVisionOptions

public VisionOptions getVisionOptions()
The options a BarcodeScanner needs to scan the way these options describe: a copy of the ones passed to visionOptions(VisionOptions) (or the defaults), plus the accepted formats(String...) unless those options name formats of their own, plus strict(boolean) when it was called. So new BarcodeScanner(options.getVisionOptions()) in a pipeline of your own detects exactly what CodeScanner.scan(CodeScannerOptions) would. Each call returns a new object.

Returns

the analyzer configuration, never null