QRCodeReaderView
QRCodeReaderView copied to clipboard
Using QRCodeReaderView in Fragments
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!
Hi Carlos,
I'll check it when I have some free time. Did you try in other different devices?
Thanks, best regards.
Yes I did. non results.
I cant understand why not?. because fragments get destroyed and recreated each time.
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!
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.
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();
}
}
Just copy QRCodeReaderView class to your project and fix it there