dlazaro66 / QRCodeReaderView

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
1.9k stars 491 forks source link

Exception while initialising qrcodereader view. #125

Open himgupta opened 7 years ago

himgupta commented 7 years ago

Hi,

I am getting below exception when initialising camera view.I am using it in dialog fragment in framelayout.Below are the exception logs for that.:

06-22 11:18:11.524 / D/com.dlazaro66.qrcodereaderview.QRCodeReaderView: surfaceCreated 06-22 11:18:11.524 / I/com.google.zxing.client.android.camera.open.OpenCameraInterface: Opening camera #0 06-22 11:18:11.534 / I/CameraConfiguration: Display at: 90 06-22 11:18:11.534 / I/CameraConfiguration: Camera at: 90 06-22 11:18:11.534 / I/CameraConfiguration: Final display orientation: 0 06-22 11:18:11.534 / I/CameraConfiguration: Clockwise rotation from display to camera: 0 06-22 11:18:11.534 / I/CameraConfiguration: Screen resolution in current orientation: Point(772, 200) 06-22 11:18:11.534 / I/CameraConfiguration: Supported preview sizes: 640x480 352x288 320x240 06-22 11:18:11.534 / I/CameraConfiguration: Found best approximate preview size: Point(640, 480) 06-22 11:18:11.534 / I/CameraConfiguration: Camera resolution: Point(640, 480) 06-22 11:18:11.534 / I/CameraConfiguration: Supported preview sizes: 640x480 352x288 320x240 06-22 11:18:11.534 / I/CameraConfiguration: Found best approximate preview size: Point(640, 480) 06-22 11:18:11.534 / I/CameraConfiguration: Best available preview size: Point(640, 480) 06-22 11:18:11.534 / I/CameraConfiguration: Preview size on screen: Point(640, 480) 06-22 11:18:11.544 / I/CameraConfiguration: Initial camera parameters: picture-size-values=640x480,352x288,320x240;prop-facing=back;preview-fps-range=5,30;min-exposure-compensation=-6;vertical-view-angle=42.5;horizontal-view-angle=54.8;whitebalance=auto;jpeg-thumbnail-height=384;jpeg-quality=90;preview-format-values=yuv420sp,yuv420p,rgba8888;jpeg-thumbnail-quality=90;focus-mode=fixed;preview-format=yuv420sp;preview-size=640x480;focal-length=4.31;video-frame-format=yuv420p;picture-format-values=jpeg;max-exposure-compensation=6;exposure-compensation=0;preview-frame-rate-values=30,24,20,15,10,5;exposure-compensation-step=0.5;prop-orientation=90;preview-frame-rate=24;focus-mode-values=fixed;picture-size=640x480;jpeg-thumbnail-width=512;whitebalance-values=auto,incandescent,daylight,twilight;picture-format=jpeg;preview-fps-range-values=(5,30);jpeg-thumbnail-size-values=320x240,0x0;preview-size-values=640x480,352x288,320x240 06-22 11:18:11.544 / I/CameraConfiguration: Requesting focus mode value from among: [auto] 06-22 11:18:11.544 / I/CameraConfiguration: Supported focus mode values: [fixed] 06-22 11:18:11.544 / I/CameraConfiguration: No supported values match 06-22 11:18:11.544 / I/AutoFocusManager: Current focus mode 'fixed'; use auto focus? false 06-22 11:18:11.544 / D/com.dlazaro66.qrcodereaderview.QRCodeReaderView: surfaceChanged java.lang.RuntimeException: startPreview failed at android.hardware.Camera.startPreview(Native Method) at com.google.zxing.client.android.camera.CameraManager.startPreview(CameraManager.java:202) at com.dlazaro66.qrcodereaderview.QRCodeReaderView.surfaceChanged(QRCodeReaderView.java:250) at android.view.SurfaceView.updateWindow(SurfaceView.java:583) at android.view.SurfaceView.access$000(SurfaceView.java:86) at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175).

Below are the parameters while initialising qrcodeview.

    qrCodeReaderView.setQRDecodingEnabled(true);
    // Use this function to change the autofocus interval (default is 5 secs)
    qrCodeReaderView.setAutofocusInterval(2000L);

    // Use this function to enable/disable Torch
    qrCodeReaderView.setTorchEnabled(true);

    // Use this function to set front camera preview

// qrCodeReaderView.setFrontCamera();

    // Use this function to set back camera preview
    qrCodeReaderView.setBackCamera();

qrCodeReaderView.setOnQRCodeReadListener(this);

kimosabi77 commented 7 years ago

I'm seeing the same error, specifically on the Xiaomi 1s and Oppo R5

dlazaro66 commented 7 years ago

Can you try to restart your devices after you get that? I saw similar issues time ago

tomerpetel commented 7 years ago

I think I'm having the same issue. Mine occurs mainly in Xiaomi devices (~80%) and in Android 5.0. follow this link for full Fabric report (stack, OS and Android versions)

Help please :)

tomerpetel commented 7 years ago

Had some progress investigating this bug. Pre Android 6 Xiaomi devices has its own runtime permission system (see snapshot) when first opening the camera (getting opened before onResume, I guess though the view element com.dlazaro66.qrcodereaderview.QRCodeReaderView) it asks for permissions and if you hit deny the application will crash (ContextCompat.checkSelfPermission returns true so no way to check it) and will continue crashing after a restart