ZXing only recognizes QR-Code

匆匆过客 提交于 2021-01-06 14:18:26

问题


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):

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


回答1:


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.



来源:https://stackoverflow.com/questions/34589203/zxing-only-recognizes-qr-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!