Android Question [B4X] Barcode Reader problem

cwt

Active Member
Licensed User
Longtime User
I am implementing this barcode reader in my Android app and have a problem with different devices.

The problem occurs in this sub of the barcode reader code:
B4X:
Private Sub CreateDetector (Codes As List)
    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)
    If operational = False Then
        toast.Show("Failed to create detector")
    End If
    btnStartStop.Enabled = operational
End Sub
The code works fine on one of my test phones, a Samsung Galaxy S10 with Android 11.0 - but I get "Failed to create detector" on another test phone, Samsung Galaxy S4 with Android 5.01.

Is this an Android version problem or possibly something else? Any fix?
 
Top