Android Question Bluetooth StartDiscovery Limit Time

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

Bluetooth: is there a way to limit the time startdiscovery is trying to connect (e.g. 2 min)?
It seems "Trying to connect..." is running long time if the HC-05 (for this example) is not reachable.

Code Snippet
B4X:
Public Sub Connect
    admin.StartDiscovery
    connecting = True
    CallSub(Main, "SetState")
End Sub

Private Sub admin_DeviceFound (Name As String, MacAddress As String)
    Log($"Device found: ${Name}"$)
    If Name = "HC-05" Then
        Log("Trying to connect...")
        admin.CancelDiscovery
        serial.Connect(MacAddress)
    End If
End Sub

Private Sub admin_DiscoveryFinished
    connecting = False
End Sub
 
Top