1

我正在使用 Zxing Lib 扫描二维码和条形码。我的代码在二维码上运行良好,但不幸的是它也不适用于条形码。

    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.setPackage("com.google.zxing.client.android");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);

任何帮助都会非常显着。在我的应用程序中,我无法使用 InTENTINTEGRATOR

在 zxing LIB 中提供了以下格式-

       static final Collection<BarcodeFormat> PRODUCT_FORMATS;
       static final Collection<BarcodeFormat> ONE_D_FORMATS;
       static final Collection<BarcodeFormat> QR_CODE_FORMATS =         EnumSet.of(BarcodeFormat.QR_CODE);
    static final Collection<BarcodeFormat> DATA_MATRIX_FORMATS = EnumSet.of(BarcodeFormat.DATA_MATRIX);
     static {
    PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A,
                             BarcodeFormat.UPC_E,
                             BarcodeFormat.EAN_13,
                             BarcodeFormat.EAN_8,
                             BarcodeFormat.RSS_14);
ONE_D_FORMATS = EnumSet.of(BarcodeFormat.CODE_39,
                           BarcodeFormat.CODE_93,
                           BarcodeFormat.CODE_128,
                           BarcodeFormat.ITF);
ONE_D_FORMATS.addAll(PRODUCT_FORMATS);

}

4

2 回答 2

1

你用它来扫描条码

private void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1]);
        } else if (points.length == 4
                && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult
                        .getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and
            // metadata
            drawLine(canvas, paint, points[0], points[1]);
            drawLine(canvas, paint, points[2], points[3]);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(point.getX(), point.getY(), paint);
            }
        }
    }
}

还要检查这个

 private boolean encodeContentsFromZXingIntent(Intent intent) {
 // Default to QR_CODE if no format given.
String formatString = intent.getStringExtra(Intents.Encode.FORMAT);
format = null;
if (formatString != null) {
  try {
    format = BarcodeFormat.valueOf(formatString);
  } catch (IllegalArgumentException iae) {
    // Ignore it then
  }
}
if (format == null || format == BarcodeFormat.QR_CODE) {
  String type = intent.getStringExtra(Intents.Encode.TYPE);
  if (type == null || type.length() == 0) {
    return false;
  }
  this.format = BarcodeFormat.QR_CODE;
  encodeQRCodeContents(intent, type);
} else {
  String data = intent.getStringExtra(Intents.Encode.DATA);
  if (data != null && data.length() > 0) {
    contents = data;
    displayContents = data;
    title = activity.getString(R.string.contents_text);
  }
}
return contents != null && contents.length() > 0;

}

于 2013-03-21T06:51:46.877 回答
0

您可以尝试更改扫描模式。尝试类似:

intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

或者

intent.putExtra("SCAN_MODE", "ONE_D_MODE");

您可以在以下页面上找到更多信息: https ://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java

于 2013-03-21T06:58:33.943 回答