BarcodeScanner

public interface BarcodeScanner extends Closeable, LifecycleObserver

Recognizes barcodes (in a variety of 1D and 2D formats) in a supplied InputImage.

A BarcodeScanner is created via getClient(BarcodeScannerOptions) or getClient(). The default option is not recommended because it tries to scan all barcode formats, which is slow. For example, the code below creates a barcode scanner for FORMAT_PDF417.

 BarcodeScanner barcodeScanner =
      BarcodeScanning.getClient(
          new BarcodeScannerOptions.Builder()
              .setBarcodeFormats(Barcode.FORMAT_PDF417)
              .build()); 

To perform barcode scanning in an image, you first need to create an instance of InputImage from a Bitmap, ByteBuffer, etc. See InputImage documentation for more details. For example, the code below creates an InputImage from an Image.

 InputImage image = InputImage.fromMediaImage(mediaImage, rotationDegrees); 

Then the code below can scan barcodes in the supplied InputImage.

 Task<List<Barcode>> task = barcodeScanner.process(image);
 task.addOnSuccessListener(...).addOnFailureListener(...); 

Public Method Summary

abstract void
close()
Closes the scanner and releases its resources.
abstract Task<List<Barcode>>
process(InputImage image)
Detects barcodes from the supplied image.

Inherited Method Summary

Public Methods

public abstract void close ()

Closes the scanner and releases its resources.

public abstract Task<List<Barcode>> process (InputImage image)

Detects barcodes from the supplied image.

Create an InputImage object using one of InputImage's factory methods. See InputImage documentation for more details.

To get the best detection result, we recommend the following:

Returns
  • a Task that asynchronously returns a List of scanned Barcodes. An empty list is returned by the Task if nothing is found.