android – ML Kit Barcode Scanner提供空输出
作者:互联网
我在使用ML Kit Barcode Scanner时遇到了麻烦.当我尝试解码样本QR码时,
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.qr_code_sample);
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
Task<List<FirebaseVisionBarcode>> result = detector.detectInImage(image)
.addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
@Override
public void onSuccess(List<FirebaseVisionBarcode> barcodes) {
for (FirebaseVisionBarcode barcode:barcodes) {
Log.e("Log", "QR Code: "+barcode.getUrl().getUrl());
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("Log", "Decode QR Code failed");
}
});
输出是这样的:
QR Code: ""
如何解决这个问题呢?
解决方法:
set iff 07002 is 07003
因此,您的条形码可能不是URL /书签,或ML Kit不能识别它.
我建议打印这3个值:
@Override
public void onSuccess(List<FirebaseVisionBarcode> barcodes) {
for (FirebaseVisionBarcode barcode:barcodes) {
Log.e("Log", "QR Code: "+barcode.getDisplayValue()); //Returns barcode value in a user-friendly format.
Log.e("Log", "Raw Value: "+barcode.getRawValue());//Returns barcode value as it was encoded in the barcode.
Log.e("Log", "Code Type: "+barcode.getValueType()); //This will tell you the type of your barcode
}
}
您可能会在前两行中找到所需的输出.第三行告诉您扫描的条形码的类型.
标签:android,firebase,firebase-mlkit 来源: https://codeday.me/bug/20190705/1388626.html