Currently my BT app is hard coded for the expected BT name (HC-05). I wish to be able to select from a range of paired BT devices (with the same or different names - obviously each with a unique MAC address)
On the last page of the thread, there is a suggestion to use a 'map' to prevent duplicates. I cant get this to work - I wont post code as I am just guessing and cant figure out how to implement this......
Would someone be kind enough to update the original example, using a map to prevent duplicates in the BT device list?
This is the bit of code from 'Bluetoothmanager' (class) where devices are added to a list:
B4X:
Private Sub Admin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
nm.Name = Name
nm.Mac = MacAddress
foundDevices.Add(nm)
End Sub
Unfortunately the list has multiple identical entries.....
Private Sub Admin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
nm.Name = Name
nm.Mac = MacAddress
foundDevices.Put(nm.Name, nm)
End Sub
You can convert it back to a list when needed:
B4X:
Dim devices As List
devices.Initialize
For Each nm As NameAndMac in foundDevices.Values
devices.Add(nm)
Next