2013-03-21 251 views
1

我正在使用Zxing Lib掃描QR碼和條碼。我的代碼對於QR代碼運行得非常好,但不幸的是它不適用於條碼。條碼掃描

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

在斑馬線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); 

}

+0

您還沒有定義的 「不工作」!爲什麼你不能使用IntentIntegrator?它只是完成你發佈的內容,或多或少,並且正確地做。 – 2013-03-21 09:41:59

+0

@SeanOwen ..感謝您的回覆。當我使用IntentIntegrator然後它會要求用戶安裝條碼scnner(第三方應用程序),但在我的應用程序中不應該有任何第三方應用程序 – DJhon 2013-03-21 10:57:47

+0

呃,你爲什麼使用intents呢?這僅適用於訪問第三方應用程序。 – 2013-03-21 12:28:16

回答

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

+0

@ Sandyiscool ...感謝您的快速響應,但形式最後3天,即72小時我搜索了所有的博客和教程..注意到是我的工作......甚至你的建議是不適合我...我在一個很大的混亂... PLZ幫助我 – DJhon 2013-03-21 07:58:21

+0

你是否嘗試不設置任何明確的格式,即發送的意圖沒有手動設置「SCAN_MODE」屬性?如果您正在嘗試閱讀的條形碼符合zxing圖書館提及的標準條形碼格式,則應該讀取它。 – sandyiscool 2013-03-21 09:08:05

+0

@ sandy ...我爲您的查詢編輯了我的問題 – DJhon 2013-03-21 10:20:18

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; 

}

+0

@Maya ,,你的迴應真的很明顯,但我要求掃描條形碼Zxing LIB – DJhon 2013-03-21 07:40:34

+0

格式已在ZXing Lib中定義。那麼爲什麼我們在這裏定義 – DJhon 2013-03-21 08:54:10

+1

這與掃描條形碼無關。它與編碼它們有關。 – 2013-03-21 09:41:23