Android Question BluetoothAdmin and insecure connections

luke2012

Well-Known Member
Licensed User
Hi to all,
I'm testing bluetooth insucure connections using the @timwil very useful tutorial :)

https://www.b4x.com/android/forum/threads/bluetooth-printing-via-spp.17692/

All works fine if I connect to the bluetooth device with the first Android device, but a second Android device cannot connect to the same bluetooth device using the same bluetooth connection.

See the Sub within tutorial that implement the bluetooth insecure connection:

B4X:
'*** Starter
Sub Process_Globals 
       Dim cmp20 As Serial
       Dim printer As TextWriter
end sub

'*** Main
Sub StartPrinter
    Dim PairedDevices As Map
    Dim L As List
    Dim Res As Int

    'ToastMessageShow("Start Printer.....",True)

    PairedDevices.Initialize

    Try
        PairedDevices = Starter.cmp20.GetPairedDevices
    Catch
        Msgbox("Getting Paired Devices","Printer Error")
        Starter.printer.Close
        Starter.cmp20.Disconnect
    End Try

    If PairedDevices.Size = 0 Then
        Msgbox("Error Connecting to Printer - Printer Not Found","")
        Return
    End If

    If PairedDevices.Size = 1 Then
        Try
            Starter.cmp20.ConnectInsecure(Starter.btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
        Catch
            Msgbox("Connecting","Printer Error")
            Starter.printer.Close
            Starter.cmp20.Disconnect
        End Try
    Else
        L.Initialize

        For i = 0 To PairedDevices.Size - 1
            L.Add(PairedDevices.GetKeyAt(i))
        Next

        Res = InputList(L, "Choose device", -1)

        If Res <> DialogResponse.CANCEL Then
            Starter.cmp20.Connect(PairedDevices.Get(L.Get(Res)))
        End If
    End If 
End Sub

This is because the bluetooth protocol allow one connection at time right?

So in my case if I want to allow multiple android device connections I have to open the connection, send data to BT device and than close the connection for each Android device that connect to the BT device to avoid the concurrent device connections.

It is right?
 
Top