Google Zxing怎样实现扫描二维码、条形码,具体参考我
这里主要说一下,怎样选择不同的模式。
Zxing 默认支持扫描二维码、条形码两种功能,但是因为项目要求,禁止扫描二维码。那么怎样禁止扫描二维码呢?
修改源代码里面的DecodeThread.java文件即可。
注释掉decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); 这句代码
源代码如下:
package com.jingu.app.zxing.decoding;
import java.util.Hashtable;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import android.os.Handler;
import android.os.Looper;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.ResultPointCallback;
import com.jingu.app.main.activity.MipcaActivityCapture;
/**
* This thread does all the heavy lifting of decoding the images. �����߳�
*/
final class DecodeThread extends Thread
{
public static final String BARCODE_BITMAP = "barcode_bitmap";
private final MipcaActivityCapture activity;
private final Hashtable<DecodeHintType, Object> hints;
private Handler handler;
private final CountDownLatch handlerInitLatch;
DecodeThread(MipcaActivityCapture activity, Vector<BarcodeFormat> decodeFormats, String characterSet,
ResultPointCallback resultPointCallback)
{
this.activity = activity;
handlerInitLatch = new CountDownLatch(1);
hints = new Hashtable<DecodeHintType, Object>;<pre name="code" class="java"> // 这里选择不同的模式,ONE_D_FORMATS是条形码、QR_CODE_FORMATS是二维码,<span style="font-family: Arial, Helvetica, sans-serif;">根据需要进行注释。</span>
if (decodeFormats == null || decodeFormats.isEmpty())
{
decodeFormats = new Vector<BarcodeFormat>();
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
// <span style="color:#ff0000;">decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);</span>
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
if (characterSet != null)
{
hints.put(DecodeHintType.CHARACTER_SET, characterSet);
}
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
Handler getHandler()
{
try
{
handlerInitLatch.await();
}
catch (InterruptedException ie)
{
// continue?
}
return handler;
}
@Override
public void run()
{
Looper.prepare();
handler = new DecodeHandler(activity, hints);
handlerInitLatch.countDown();
Looper.loop();
}
}