Simultaneous Barcode Scanning

Prerequisites

  1. Set up the required Google Play Services like described in Android Developer Guides .
  2. You may choose to only compile the required Mobile Vision API (instead of all Google Play Services), which would be: "com.google.android.gms:play-services-vision:X.Y.Z"
  3. The minimum required version of the Mobile Vision API is 7.8.0, however it is strongly recommended to use the latest API - see also the Mobile Vision Release Notes for details.
  4. Optional: Check if the Android device has the requirements installed like described in the Android Setup Guide to check whether the device is ready.

Enabling Simultaneous Barcode Scanning

The additional barcode scanning is available for every module, and it can be enabled by calling the following:

Enable Simultaneous Barcode Scanning
scanView.enableBarcodeDetection(new NativeBarcodeResultListener() {
        public void onBarcodesReceived(SparseArray<Barcode> barcodes) {
            // you could simply iterate the found barcodes

            for(int i = 0; i < barcodes.size(); i++){
                Barcode thisCode = barcodes.valueAt(i);
                Log.d(TAG, "found barcode: " + thisCode.rawValue );
                // do something else with this barcode
            }
        }
    });

The NativeBarcodeResultListener will be called everytime a result is found, e.g. it will be totally independent from the results of the selected module. It may happen that you get more results than with the result listener of the module, or you even get none.

Disabling Simultaneous Barcode Scanning

The simultaneous barcode scanning is disabled by default.
If you have enabled it and decide to stop it, you have to disable it explicitly like in the code bellow.

Disabling Simultaneous Barcode Scanning
scanView.disableBarcodeDetection();

Known issue: Barcode Detector won’t work

If you do not get results from the barcode reader, and find a log message

Barcode Detector not operational on the Device

in the Logcat output, the Android Device is not ready for barcode scanning.

This may have multiple reasons. The device needs however internet connection to download missing dependencies. Make sure the dependencies are added in gradle (this should trigger the download of required files).

For details see also the Android Barcode Documentation .

Defining Vision Dependency in the AndroidManifest.xml
 <meta-data  tools:node="replace"
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="barcode"/>

You can also check on runtime, whether the Android device is ready. The Android Setup Guide describes how to add and ensure devices have the Google Play services APK.