The following extracted code worked as expected in November of 2014:
Device: Nexus 7 (2013)
Android version: 6.0
Android security patch level: November 1, 2015
B4A Version: 5.50
Serial library version: 1.23
Since the code was originally written and tested, there have been multiple version updates to Android and B4A.
Current issue summary:
Between the time that BTAdmin.StartDiscovery starts and BTAdmin_DiscoveryFinished fires, no devices are found. BTAdmin_DeviceFound never fires. No error messages are logged. Blue Tooth is powered on, initialized, and the native Android Blue Tooth settings dialogs show that there are 3 devices that are discoverable. This behavior is consistent on 4 identically configured tablets.
How do I get the current serial library to discover Blue Tooth devices?
B4X:
Sub Process_Globals
Dim BTAdmin As BluetoothAdmin
Dim BTSerial1 As Serial
Dim BTFoundDevices As List
Type BTNameAndMac (Name As String, MAC As String)
Dim BTConnectedDevice As BTNameAndMac
Dim BTAStream As AsyncStreams
End Sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Set up the Bluetooth reader
If FirstTime Then
BTAdmin.Initialize("BTAdmin")
BTSerial1.Initialize("BTSerial1")
End If
End Sub
B4X:
Sub btnBTConnect_Click
BTFoundDevices.Initialize
If BTAdmin.StartDiscovery = False Then
ToastMessageShow("Error starting discovery process.", True)
Else
ProgressDialogShow("Searching for devices...")
End If
End Sub
Sub BTAdmin_DiscoveryFinished
ProgressDialogHide
If BTFoundDevices.Size = 0 Then
ToastMessageShow("No device found.", True)
Else
Dim l As List
l.Initialize
For i = 0 To BTFoundDevices.Size - 1
Dim nm As BTNameAndMac
nm = BTFoundDevices.Get(i)
l.Add(nm.Name)
Next
Dim res As Int
res = InputList(l, "Choose device to connect.", -1)
If res <> DialogResponse.CANCEL Then
BTConnectedDevice = BTFoundDevices.Get(res)
ProgressDialogShow("Trying to connect to: " & BTConnectedDevice.Name & " (" & BTConnectedDevice.Mac & ")")
BTSerial1.Connect(BTConnectedDevice.Mac)
End If
End If
End Sub
Sub BTAdmin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
Dim nm As BTNameAndMac
nm.Name = Name
nm.Mac = MacAddress
BTFoundDevices.Add(nm)
ProgressDialogShow("Searching for devices (~ device found)...".Replace("~", BTFoundDevices.Size))
End Sub
Device: Nexus 7 (2013)
Android version: 6.0
Android security patch level: November 1, 2015
B4A Version: 5.50
Serial library version: 1.23
Since the code was originally written and tested, there have been multiple version updates to Android and B4A.
Current issue summary:
Between the time that BTAdmin.StartDiscovery starts and BTAdmin_DiscoveryFinished fires, no devices are found. BTAdmin_DeviceFound never fires. No error messages are logged. Blue Tooth is powered on, initialized, and the native Android Blue Tooth settings dialogs show that there are 3 devices that are discoverable. This behavior is consistent on 4 identically configured tablets.
How do I get the current serial library to discover Blue Tooth devices?