I have notice searching for Bluetooth will display numerous duplicates anywhere from 2 to 5 same name and ID.
Is this a bug with Serial library?
B4X:
Sub Admin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
nm.Initialize
nm.Name = Name
nm.Mac = MacAddress
If foundDevices.IsInitialized = False Then foundDevices.Initialize
foundDevices.Add(nm)
ProgressDialogShow2("Searching for devices (~ device found)...".Replace("~", foundDevices.Size), False)
End Sub
I have notice searching for Bluetooth will display numerous duplicates anywhere from 2 to 5 same name and ID.
Is this a bug with Serial library?
B4X:
Sub Admin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
nm.Initialize
nm.Name = Name
nm.Mac = MacAddress
If foundDevices.IsInitialized = False Then foundDevices.Initialize
foundDevices.Add(nm)
ProgressDialogShow2("Searching for devices (~ device found)...".Replace("~", foundDevices.Size), False)
End Sub
I'm not sure if is a bug or not, but that shouldn't affect your app in any way, you can just simply check if the MacAddress is already added to your list and skip it if it is already in the list.
I'm not sure if is a bug or not, but that shouldn't affect your app in any way, you can just simply check if the MacAddress is already added to your list and skip it if it is already in the list.
But I wonder what will happen if two identical Bluetooth device with same name and Id are being discovered and when connecting will it communicate with both device?
But I wonder what will happen if two identical Bluetooth device with same name and Id are being discovered and when connecting will it communicate with both device?
Update: Tried it on Samsung S6 it show numerous duplicates only with available Mac Name.
Tried it on Alcatel and it shows numerous duplicates with or without available Mac Name.
Did you guys test the Serial Library for Discoveries?
This means that the OS sent duplicate broadcasts. Should be trivial to remove duplicates. You can use a Map or B4XSet or List.IndexOf to remove duplicates.
This behavior is normal. I had to write filters to filter all that "noise" out.
Here is how I fixed it: (I am sure there are easier ways with Maps and Lists, but when I wrote this I wasnt familiar at all with those)
B4X:
Sub Admin_DeviceFound (Name As String, MacAddress As String)
Dim I As Int
MACDetected = False
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
nm.Name = Name
nm.Mac = MacAddress
For I = 0 To 254 Step 1
If MACArray(I) = MacAddress Then
MACDetected = True
End If
Next
If MACDetected = False Then
MACArray(MacPosition) = MacAddress
foundDevices.Add(nm)
ProgressDialogShow2("Searching for devices (~ found)...".Replace("~", foundDevices.Size), False)
MacPosition = MacPosition + 1
End If
End Sub
The above code works, again it would be easier with a Map. But either way, it gets around the problem.
ivate Sub Admin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
nm.Name = Name
nm.Mac = MacAddress
foundDevices.Put(MacAddress,nm) ' where foundDevices is a Map in the Adminclass and the map should be initialized in the Initialize sub ob the Class.
End Sub
This means that the OS sent duplicate broadcasts. Should be trivial to remove duplicates. You can use a Map or B4XSet or List.IndexOf to remove duplicates.
Ok, thanks for the answer. One annoying thing about this issue is the DiscoveryFinished event can get triggered twice and i seen it happened 2 in every 30 attempts. My inputlist gets called twice because of this.