-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera is not released when using the CameraBarcodeReaderView in xaml #164
Comments
Took me a while to get around this same issue. I found the problem to be that it isn't calling CameraBarcodeReaderViewHandler.DisconnectHandler() when you leave a page. Here is what I ended up with. I have been able to continuously reuse the camera but most of my testing with this was done on a Maui Community Toolkit Popup that uses the CameraBarcodeReaderView control.
|
Unfortunately, this still doesn't release the camera and my NFC is not turning itself back on by disconnecting. I still have to call Or else my NFC will not work again until the app is force closed. |
Had the same issue. Add this to the constructor of the page that is using the barcode reader.
Source /Credit : #118 (comment) |
i think i am also seeing the same issue.... i just tried the last idea i added this line: |
can you please show where you add this code to fix the control ? |
We use a simple Xaml page that is only for our barcode scanning. Once the Xaml is pushed to the navigation stack here is what we do.
The main thing is I had to manually open and close the camera preview. So the navigation.Push that opens then xaml waits for the We also only have to support Android so there is no IOS logic here that may or may not be necessary. |
i partly follow this but can you help me a bit more? can i apply this code to a content page ? it looks like it will work for the most part. is _scanComplete a view model that you are injecting ??? sorry if i am slow here i have only recently gotten into maui and android so there is a lot i am trying to understand here.... perhaps a sample application that demos your basic setup might help ? |
That is almost the entire page but I can give you the whole page.
here is the Xaml
And here is how I display it
The only things that the view model contains is the top and bottom text. |
when i try to add the using for AndroidX i get red squiggles and an error message. do i need to make this in the platform folder ?? or is there some other trick i am missing ?? |
I don't know of anything that would be causing this. Maybe something is not setup in the application correctly without being able to troubleshoot it I cannot be of that much assistance. |
is the code from your content page in the main folders or in the platform/android folder ? |
Nope, mine is in a scanning/qrcodescanner directly under the main project. I know putting some things in the platform android is how you solve certain problems. But glad you are able to get it working I hope it does what you want. |
well when i tried to put the code in the platform folder that created a new set of problems... not sure what the heck to try now..... i may just use an actual barcode scanner .... this is not working for me... and i know the answer is close,.....but just past my understanding of how to make it work!!! |
and i think i am close to having this working..... i have a bug or something .... i can get the camera back without closing the app. i created a new app, i pulled in the code i did find that i had to put in #if ANDROID blocks in the code for the content page. this seems like it is almost working now! |
nope, not working for me.... i keep getting the black preview box. i have using the flyout menu to open the page and first time it works, second time not so much. |
I think that i might now have the thing.... i was not trying the one thing that yo0u are doing different.... i hope this solves it! |
so i can not use the view from a page that uses flyout navigation! that was the key here.... i have to use the push / read / pop that you used! THANK YOU! |
I had similar issue and adding the above code to close the camera worked out really well for me. But then I had one more issue. Thanks |
I have the same issue where if the camera view is in a ContentPage, it works the first time the page is navigated to but fails to reinitialize after navigating away and back again. It'd be nice if there was a Close() method to call on OnDisappearring and/or an Initialize() method to call on OnAppearing. Or if the library just handled this automatically :) I've managed to work around the issue using the suggested solution above except that on navigating to the page in the OnApprearing method I call preview?.Open();
|
in my app the solution was to use the Community toolkit popup control. yes an update to this package that made this automatic or un needed would be preferred. |
In my case, I am able to close the camera and reinitialize it. In all scenarios it is working fine. In our app we use laser scan. Laser scan is working fine in all scenarios. The issue is, when I scan with camera(Zxing) and lock the screen and unlock the screen, then tried with laser scan, but it did not trigger the laser. I have to kill the app or open the camera(Zxing) and then laser started working. I checked whether the camera instance is not closed after screen unlock, but it closed the camera. I checked if reinitialization of laser is not happening, but that is also working. I am unable to understand here what could be issue to think of solution. Please provide your ideas if anyone faced this kind of issue. Thanks in advance. |
I am using the CameraBarcodeReaderView in my xaml for barcodesDetected.
We also use NFC for scanning some card, when we open the barcode scanner it is disabling the NFC. I believe this is part of certain android devices to disable the NFC when the camera is opened. The NFC normaly gets enabled again when the camera is closed or released. However there is no way to release the camera when using the CameraBarcodeReaderView.
I was able to verify that releasing it fixes the problem through reflection but this causes other issues with the CameraPreview if you try to re-open the scanner it just stays black. Here is the reflection for what it is worth.
The text was updated successfully, but these errors were encountered: