Class 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));
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfacing(CameraFacing value) Selects which camera the scanner opens.Restricts which symbologies are accepted, using theBarcodeFormatconstants.String[]getHint()getTitle()The options aBarcodeScannerneeds to scan the way these options describe: a copy of the ones passed tovisionOptions(VisionOptions)(or the defaults), plus the acceptedformats(String...)unless those options name formats of their own, plusstrict(boolean)when it was called.Sets the instruction shown below the preview.booleanisStrict()booleanstrict(boolean value) Accepts a code only when two frames read it identically.Sets the scanner form's title.torchButton(boolean value) Whether to offer a torch toggle.visionOptions(VisionOptions value) Passes analyzer options through to the underlyingBarcodeScanner, which is how an iOS build selectsVisionBackends.mlKitBarcodeScanning()instead of Apple Vision.
-
Constructor Details
-
CodeScannerOptions
public CodeScannerOptions()
-
-
Method Details
-
title
Sets the scanner form's title.- Parameters:
value- the title, ornullfor no title- Returns:
- this options object
-
hint
Sets the instruction shown below the preview.- Parameters:
value- the instruction, ornullto show none- Returns:
- this options object
-
formats
Restricts which symbologies are accepted, using the
BarcodeFormatconstants. 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- accepted format constants; empty ornullaccepts every format- Returns:
- this options object
-
facing
Selects which camera the scanner opens.- Parameters:
value- the camera to use, ornullfor the back camera- Returns:
- this options object
-
torchButton
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 istrue.- Parameters:
value- whether the toggle may be shown- Returns:
- this options object
-
strict
Accepts a code only when two frames read it identically. By default this applies to PDF417 codes alone;
trueextends it to every symbology andfalseturns 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 aBarcodeScannerbuilt fromgetVisionOptions(), and overrides astrictBarcodesset on the options passed tovisionOptions(VisionOptions).- Parameters:
value- whether two matching reads are required- Returns:
- this options object
-
visionOptions
Passes analyzer options through to the underlyingBarcodeScanner, which is how an iOS build selectsVisionBackends.mlKitBarcodeScanning()instead of Apple Vision.- Parameters:
value- analyzer configuration, ornullfor the defaults- Returns:
- this options object
-
getTitle
- Returns:
- the scanner form's title, possibly
null
-
getHint
- Returns:
- the instruction shown below the preview, possibly
null
-
getFormats
- Returns:
- defensive copy of the accepted formats; empty accepts all
-
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
The options aBarcodeScannerneeds to scan the way these options describe: a copy of the ones passed tovisionOptions(VisionOptions)(or the defaults), plus the acceptedformats(String...)unless those options name formats of their own, plusstrict(boolean)when it was called. Sonew BarcodeScanner(options.getVisionOptions())in a pipeline of your own detects exactly whatCodeScanner.scan(CodeScannerOptions)would. Each call returns a new object.- Returns:
- the analyzer configuration, never
null
-