1.我们这里使用的还是二维码的库
在需要的onActivityResult中加入这个,记得需要找到mBitmap 这个bitmap文件
MultiFormatReader multiFormatReader =new MultiFormatReader();
Hashtable hints =new Hashtable(2);
Vector decodeFormats =new Vector();
if (decodeFormats ==null || decodeFormats.isEmpty()) {
decodeFormats =new Vector();
// 这里设置可扫描的类型,我这里选择了都支持
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
multiFormatReader.setHints(hints);
Result rawResult =null;
try {
//保证在这里的mBitmap在上文中能找到就行
rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(mBitmap))));
}catch (NotFoundException e) {
e.printStackTrace();
}
if (rawResult !=null) {
String text = rawResult.getText();
Toast.makeText(this, text +"", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this,"解析失败", Toast.LENGTH_SHORT).show();
}
}