0
我正在實施一種方法來解碼QR碼並返回包含在Android應用程序代碼中的字符。 我想運行此方法,直到QR碼解碼成功並返回空值。在Android應用程序中使用循環解碼QR碼的方法
它在第一次循環運行正確。 但是,當它在第一個循環中讀取失敗時,它很少從第二個循環開始解碼代碼。 有時它也會陷入無限循環。
如果您有一些提示,請讓我知道。
public String readQRCode(Bitmap file) {
Reader reader = new MultiFormatReader();
Result result = null;
do {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_IMAGE);
Toast.makeText(this, "Please try again", Toast.LENGTH_LONG).show();
LuminanceSource source = new RGBLuminanceSource(file);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
source));
// Decode
try {
result = reader.decode(binaryBitmap);
} catch (NotFoundException e) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_IMAGE);
Toast.makeText(this, "Please try again", Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
} while (result == null || result.getText() == null);
return result.getText();
}
非常感謝您的幫助!我刪除了readQRCode方法,並在onActivityMethod中編寫了與「result」(無循環)相關的代碼。然後我終於可以解決問題了。 – Benben 2012-07-28 22:46:58