我想在我的应用程序中扫描二维码。我不想使用ZXing,因为如果用户没有此应用程序安装在设备上,它会引用Google Play。我还发现了这个:https://github.com/Gnzlt/AndroidVisionQRReader ,但我无法将其安装到Android Studio中,作者提出的所有3种方法都失败了。也许您知道其他方法(可能只需将依赖项放入gradle中)?
只需添加
compile 'com.google.zxing:core:3.2.1'
MultiFormatReader mReader = new MultiFormatReader();
Map<DecodeHintType,Object> hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);
hints.put(DecodeHintType.TRY_HARDER, true);
// select your barcode formats here
List<BarcodeFormat> formats = Arrays.asList(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
mReader.setHints(hints);
// your camera image here
Bitmap input;
int width = input.getWidth(), height = input.getHeight();
int[] pixels = new int[width * height];
input.getPixels(pixels, 0, width, 0, 0, width, height);
input.recycle();
input = null;
BinaryBitmap bb = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(width, height, pixels)));
Result result = mReader.decodeWithState(bb);
String resultString = result.getText();