Search code examples
javaandroidbarcode-scanner

Unable to scan some barcodes with Scandit SDK - Android


My code is scanning codes of a certain length but if the length is increased it doesn't scan and I don't know how to increase the length of characters of barcode. I did check the following question but wasn't sure how to use it in my code:

Scandit not recognizing a barcode

Here is my current code:

    private void showCameraScannerInMatrixMode(){
    stopScanner();
    ScanSettings settings = ScanSettings.create();
    int[] symbologiesToEnable = new int[] {
            Barcode.SYMBOLOGY_CODE128
    };

    for (int sym : symbologiesToEnable) {
        settings.setSymbologyEnabled(sym, true);
    }


    settings.setMatrixScanEnabled(true);
    settings.setMaxNumberOfCodesPerFrame(10);
    settings.setCodeRejectionEnabled(true);
    float zoomLevelInPrefs = (float)PreferenceHelper.getIntFromPreferences(Constants.INLINE_SCANDIT_SCANNER_ZOOM_CONFIG,getApplicationContext());
    float zoomLevel = zoomLevelInPrefs / 100;
    settings.setRelativeZoom(zoomLevel);
    settings.setCameraFacingPreference(ScanSettings.CAMERA_FACING_BACK);

    boolean emulatePortraitMode = !BarcodePicker.canRunPortraitPicker();
    if (emulatePortraitMode) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    scanTextOverlay.setVisibility(View.VISIBLE);
    mBarcodePicker = (BarcodePicker)findViewById(R.id.scannerView);
    mBarcodePicker.setOnScanListener(this);
    mBarcodePicker.applyScanSettings(settings);
    mBarcodePicker.setVisibility(View.VISIBLE);
    mBarcodePicker.getOverlayView().setGuiStyle(ScanOverlay.GUI_STYLE_MATRIX_SCAN);
    mBarcodePicker.getOverlayView().setVibrateEnabled(false);
    mBarcodePicker.setOnScanListener(this);
    mBarcodePicker.startScanning();
}

Here is the barcode that I am able to scan Here is the barcode that I am able to scan

This I am unable to scan This I am unable to scan


Solution

  • The relevant documentation for this is under https://docs.scandit.com/stable/android/android-active-symbols-counts.html what you should be doing in your case (you have a code with length 19 and one with length 22):

    SymbologySettings symSettings = 
    settings.getSymbologySettings(Barcode.SYMBOLOGY_CODE128);
    short[] activeSymbolCounts = new short[] {
        7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
    };
    symSettings.setActiveSymbolCounts(activeSymbolCounts);
    

    If you aren't interested in shorter codes you might want to start a bit higher than 7. As the guide states you can download the Scandit Demo app at https://play.google.com/store/apps/details?id=com.scandit.demoapp to figure out the length of each code (just go into the "Any Code" mode and scan a barcode).