Zxing找到QR码后,将其传送到handleResult功能,然后停止摄像头。如果解码的QR码已保存在我的应用中,则需要重新启动相机。如何重新启动相机?

最佳答案

如果您使用的是ZXing的ZXingScannerView,则在处理QR码和/或将结果显示给用户时,可以将stopCameraPreview()stopCamera()结合使用。当您的应用程序/用户准备再次扫描时,您只需使用setResultHandler()startCamera()调用resumeCameraPreview()

例:

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);
    }
}


希望这可以帮助 :)

10-04 23:13