ZXing找到二维码后如何重启相机

How to restart the camera in ZXing after it finds the QR code

当 Zxing 找到 QR 码时,它会将其传送到 handleResult 函数并停止相机。如果解码的二维码已经保存在我的应用程序中,我需要重新启动相机。如何重新启动相机?

如果您使用 ZXing 的 ZXingScannerView,您可以在处理 QR 码 and/or 时将 stopCameraPreview()stopCamera() 结合使用,将结果显示给您用户。当您的 app/user 准备好再次扫描时,您只需使用 startCamera()resumeCameraPreview().

调用 setResultHandler()

示例:

public void startScan() { //use this when you want to resume the camera
    if (scannerView != null) {
        scannerView.setResultHandler(this);
        scannerView.startCamera();
        rescan();
    }
}

public void stopScan() { //use this when you want to stop scanning
// it is very important to do that,
// because the camera will keep scanning codes in background
    if (scannerView != null) {
        scannerView.stopCameraPreview();
        scannerView.stopCamera();
    }
}

public void rescan() {
    if (scannerView != null) {
        scannerView.resumeCameraPreview(this);
    }
}

希望对您有所帮助:)