我在使用 ML Kit Barcode Scanner 时遇到问题。当我尝试解码示例二维码时,
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: ""
如何解决这个问题呢?