Android Question Scanned bluetooth devices appear double

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can you post the logs?

The DeviceFound events come from the OS. My guess is that the underlying Bluetooth adapter sends duplicate events. This can be solved with a Map or B4XSet:
B4X:
Private Sub Admin_DeviceFound (Name As String, MacAddress As String)
    Log(Name & ":" & MacAddress)
    Dim nm As NameAndMac = CreateNameAndMac(Name, MacAddress)
    If SetOfMacs.Contains(MacAddress) Then Return
     SetOfMacs.Add(MacAddress)
    CLV.AddTextItem($"${nm.Name}: ${nm.Mac}"$, nm)
End Sub
 
Upvote 0

Ekko

Member
Licensed User
Longtime User
Thanks Erel, I solved it with this code that you put in another post.
B4X:
Private Sub Admin_DeviceFound (Name As String, MacAddress As String)
    Log(Name & ":" & MacAddress)
    Dim nm As NameAndMac = CreateNameAndMac(Name, MacAddress)
    CLV.AddTextItem(nm.Name & CRLF & nm.Mac, nm)   
    Dim m As Map
    m.Initialize
    Dim i As Int = 0
    Do While i < CLV.GetSize
        Dim item As String = CLV.GetValue(i)
        If m.ContainsKey(item) Then
            CLV.RemoveAt(i)
            i = i - 1
        Else
            m.Put(item, "")
        End If
        i = i + 1
    Loop
End Sub
 
Upvote 1
Top