QRCodeReaderView icon indicating copy to clipboard operation
QRCodeReaderView copied to clipboard

Using QRCodeReaderView in Fragments

Open carlosharlens opened this issue 10 years ago • 6 comments

Hi,

I just use this lib on a fragment. it runs like a charm but, once container fragment lost focus, it is imposible to get qrCodeReaderView working again. Dont know why stops reading.

Please, help!.

best regards!

carlosharlens avatar Oct 31 '14 14:10 carlosharlens

Hi Carlos,

I'll check it when I have some free time. Did you try in other different devices?

Thanks, best regards.

dlazaro66 avatar Nov 05 '14 08:11 dlazaro66

Yes I did. non results.

I cant understand why not?. because fragments get destroyed and recreated each time.

carlosharlens avatar Nov 06 '14 16:11 carlosharlens

Hello guys, I got the same problem here and I've found a possible solution for you. I guess you called qrCodeReaderView.getCameraManager().stopPreview() somewhere after your fragment paused. If you did so, in some case after stop previewing the PreviewCallback implementation will be detached from camera. so the following line can fixed it magically, add them before where you call startPreview() : qrCodeReaderView.getCameraManager().getCamera().setPreviewCallback(qrCodeReaderView);

@dlazaro66 I guess you can create a method in the ReaderView class to do startPreview() and stopPreview() and added the line above into it :)

hope this help you!

HaoCherHong avatar Feb 06 '15 21:02 HaoCherHong

Got this issue as well on Samsung S3 by blocking and unblocking screen (Im using version 2.0.1). After screen unblocked, onPreviewFrame stops being called. Adding mCameraManager.setPreviewCallback(this); in startCamera method of the QRCodeReaderView fixed the issue.

ekzee avatar Sep 06 '16 04:09 ekzee

I encountered the same issue , and I found that the mCameraManager is private filed , how can I do that?

I solve this by using Reflection.

    // invoke this method before startCamera();
    private void resetPreViewCallback() {
        try {
            Field field = QRCodeReaderView.class.getDeclaredField("mCameraManager");
            field.setAccessible(true);
            CameraManager cameraManager = (CameraManager) (field.get(binding.qrCodeReaderView));
            cameraManager.setPreviewCallback(
                    (data, camera) -> binding.qrCodeReaderView.onPreviewFrame(data, camera));

        } catch (NoSuchFieldException | IllegalAccessException | SecurityException e) {
            e.printStackTrace();
        }
    }

xiejinpeng007 avatar Sep 21 '17 02:09 xiejinpeng007

Just copy QRCodeReaderView class to your project and fix it there

ekzee avatar Sep 21 '17 03:09 ekzee