Search code examples
zxinggoogle-glassbarcode-scanner

ZXing only recognizes QR-Code


I am trying to develop a barcode scanner for google glass (don't judge) using the ZXing library.

Scanning QR-Codes works perfectly fine, but I can't scan any 1D-barcodes.

This is my code:

Intent intent = new Intent(this, CaptureActivity.class);
//intent.putExtra("SCAN_MODE", "PRODUCT_MODE"); //doesn't work with or without this line
startActivityForResult(intent, SCAN_REQUEST);

Here is an example (EAN-8):
enter image description here

Scanning this with a scanner from the PlayStore works on my phone, but not using my app on the glass.


Solution

  • I found a workaround for my problem in the DecodeRunnable.java.
    By adding BarcodeFormat.EAN_8 to the list in the code below I was able to scan the barcode.

    DecodeHandler() {
      hints = new EnumMap<>(DecodeHintType.class);
      hints.put(DecodeHintType.POSSIBLE_FORMATS,
          Arrays.asList(BarcodeFormat.AZTEC, BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX));
    }
    

    You are wellcome to post your answers, because I believe there is a better way to solve this.