Android Question barcode reader stops reading

leitor79

Active Member
Licensed User
Longtime User
Hi,

I'm using this implementation of a barcode reader and it happens that, after a few minutes of running the app, it stops recognizing barcodes. I still see the camera preview, but no further codes are detected, even those ones who where previously detected. I have to kill the app and start it again. Nothing is shown in the logs.

This is the detector creation, just for quick reference. I think I could put a timer and check the isoperational status and, if it is false, call CreateDetector again? Would this be a good solution?

Regards!

B4X:
Private Sub CreateDetector (Codes As List)
    
    Try
        
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        Dim builder As JavaObject
        builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
        Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
        Dim barcodeStatic As JavaObject
        barcodeStatic.InitializeStatic(barcodeClass)
        Dim format As Int
        For Each formatName As String In Codes
            format = Bit.Or(format, barcodeStatic.GetField(formatName))
        Next
        builder.RunMethod("setBarcodeFormats", Array(format))
        detector = builder.RunMethod("build", Null)
        Dim operational As Boolean = detector.RunMethod("isOperational", Null)
        Log("Is detector operational: " & operational)
        SearchForBarcodes = operational
        
    Catch
        Log(LastException)
        ToastMessageShow(LastException, True)
    End Try

End Sub
 

leitor79

Active Member
Licensed User
Longtime User
Hi Erel, thank you for your answer.
Yes and yes... but not together. The issue is present it release mode but I've not checked the logs there, just in debug mode.
I'll try if I can catch the logs in release mode.

Regards,
 
Upvote 0
Top