Android Question Wait For Connected Bluetooth always fail

EduardoElias

Active Member
Licensed User
Longtime User
Hi there!

I have this code:

B4X:
Public Sub DirectPrint(aPrinter As String, aData As String, aBTMac As String)
    Dim PairedDevices As Map
    LocalOSerial.Initialize("DirectPrint")
    If aBTMac = "" Then
        PairedDevices = LocalOSerial.GetPairedDevices
        For i = 0 To PairedDevices.Size - 1
            Dim device As String = PairedDevices.GetKeyAt(i)
            If device.Contains(aPrinter) Then
                LogColor("yBTPrinter.DirectPrint "&aPrinter, Colors.Red)
                LocalBTMac = PairedDevices.get(device)
            End If
        Next
        If LocalBTMac = "" Then
            Return
        End If
    Else
        LocalBTMac = aBTMac
    End If

    LocalOSerial.Connect(LocalBTMac)

    Wait For DirectPrint_Connected (Success As Boolean)

    If Success Then
        LocalPrinter.Initialize(LocalOSerial.OutputStream)
        LocalPrinter.WriteLine(LocalData)
        LocalPrinter.Flush
        LocalPrinter.Close
    Else
        LogColor("Fail to Connect", Colors.Red)
    End If
    LocalOSerial.Disconnect
End Sub

and it always fail to connect.

It is a BT Printer, and I have it working on the same tablet with the same program using the "normal" way of connecting based on waiting for the Connected event.

It seems that the Wait For is not getting the event.

Thank you
 
Top