Android Question Parsing MobileVision Barcodes

colboy

Member
Licensed User
Longtime User
More a B4A question, than MobileVision, but I want to use MobileVision to parse multiple barcodes. I can see the data when it is written to the log, but I cant work out how to get at the elements I want, specifically displayValue, which contains the barcode itself. Here's how I thought it would work.

Here's the

B4X:
Sub Barcode_onBarcodeResult(success As Boolean, info As String, result As List)
    If (success=True) Then
        For forcount=0 To result.Size-1
            Dim l As Map
            l.Initialize
            l=result.Get(forcount)
            Log(l.Get("displayValue"))
        Next
    Else
    End If
End Sub

As I understand it, the result is a list of Map elements. I just want to parse out each barcode. When it gets to l=result... the program just ends, with nothing written to the log.

Thanks in advance.

Colin
 

Syd Wright

Well-Known Member
Licensed User
I think in stead you should use:
B4X:
Sub Barcode_Result(info As String, scanresults As List)
 
end Sub
and then parse the scanresults list.
 
Upvote 0

colboy

Member
Licensed User
Longtime User
Never initialize an object before you assign a different object to the same variable. The previous one is discarded.

What is the output of Log(result)?
Yes that was just clutching at straws. It looks like the list is strings, so I parse like this:

B4X:
Sub barcode_onBarcodeResult(success As Boolean, info As String, result As List)
    Dim lResult As String
    Dim lResult2 As String
    Dim lResult3 As String
    Dim lBarcodeResult As String
    Dim lBarcode As String
    Dim lCode As String
    If (success=True) Then
        For forcount=0 To result.Size-1
            lResult=result.Get(forcount)
            lResult2=GlobalFunctions.Right(lResult,lResult.Length-9)
            lResult3=GlobalFunctions.Left(lResult2,lResult2.Length-1)
            Dim lList() As String
            lList=GlobalFunctions.split(lResult3,",")
            If lList(0).StartsWith("displayValue=") Then
                lBarcodeResult=GlobalFunctions.Right(lList(0),lList(0).Length-13)
                lCode=GlobalFunctions.Left(lBarcodeResult,1)
                lBarcode=GlobalFunctions.Right(lBarcodeResult,lBarcodeResult.Length-1)
            End If
         Next
    End If
End Sub
 
Upvote 0
Top