我为Android开发了qrscanning应用程序,作为商务应用程序。我为此操作使用了Google视觉API。 QRCode扫描工作正常。 突然停止读取qrcode,但是相机正在工作。怎么找 问题是什么以及如何解决此问题?
详细信息:
假设有100个盒子,每个盒子的qr码不同(通过手机扫描100个盒子)。客户原为 扫描每个二维码并存储数据。但是平均而言, 相机停止读取qrcode(例如,在100个扫描盒中,有50个正在扫描 完成)
我曾经这样编码:
public void doScanning( boolean autoFocus, boolean isFlashLightOn)
{
try {
barcodeDetector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.QR_CODE | Barcode.DATA_MATRIX)
.build();
barcodeDetector.setFocus(1);
builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedFps(15.0f)
.setRequestedPreviewSize(1600, 1024);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder = builder.setFocusMode(
autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
}
cameraSource = builder.setFlashMode(isFlashLightOn ? Camera.Parameters.FLASH_MODE_TORCH : null).build();
cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
}
cameraSource.start(cameraView.getHolder());
} catch (IOException ie) {
ie.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
cameraSource.stop();
}
});
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
@Override
public void release() {
}
@Override
public void receiveDetections(final Detector.Detections<Barcode> detections) {
if (detections.getDetectedItems().size() != 0) {
scannedResult.post(new Runnable() {
@Override
public void run() {
scannedResult.setText(detections.getDetectedItems().valueAt(0).displayValue);
addData(detections.getDetectedItems().valueAt(0).displayValue);
}
});
}
}
});
}catch(Exception e)
{
Toast.makeText(getApplicationContext(), "L381 CAMERA NOT WORKING", LENGTH_SHORT).show();
}
}