Android Question [Solved] (BLE+BT) Elegant solution for the automatic connection

D

Deleted member 103

Guest
Hi,

My app supports two Bluetooth devices, one uses BLE and the other uses Classic Bluetooth.
Now I am looking for an elegant solution for the automatic connection setup.
The user does not have to select a device himself, he should only press a button and the app must connect to one of the two devices.
Of course I also have two different classes for the two different Bluetooth protocols.

Maybe someone has asked the question before and also has a solution for it.
 

Cableguy

Expert
Licensed User
Longtime User
Why not cycle through the specified devices trying to connect to one of them and if unable to connect to one, pass on to trying to connect to the other... Repeat if connecting lost...
 
Upvote 0
D

Deleted member 103

Guest
Why not cycle through the specified devices trying to connect to one of them and if unable to connect to one, pass on to trying to connect to the other... Repeat if connecting lost...
Thanks for the hint.
I also had the idea, but I just thought there is something else.
 
Upvote 0
D

Deleted member 103

Guest
Implementing each of the BT types in a different class is a good start. Each one should work independently and try to connect. They aren't really related to each other.
Thanks for the tip, I try my best. :)
 
Upvote 0
D

Deleted member 103

Guest
Here's my solution, I think it's elegant enough.
It's a class that manages the two Bluetooth class.
B4X:
Sub Class_Globals
    Private bt As clsBluetooth
    Private ble As clsBluetoothBle   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    
    'Classic-Bluetooth initialisieren.
    bt.Initialize(Me, "bt")

    'BLE initialisieren.
    ble.Initialize(Me, "ble")
End Sub

Public Sub ConnectDevice
    bt.ConnectDevice

    ble.ConnectDevice
End Sub

Public Sub IsConnected As Boolean
    Return bt.IsConnected Or ble.IsConnected
End Sub

#Region bt-Funktionen
Private Sub bt_DeviceNotFound
    Log("bt_DeviceNotFound")
End Sub

Private Sub bt_DeviceConnected
    Log("bt.IsConnected=" & bt.IsConnected)
End Sub
#End Region

#Region ble-Funktionen
Private Sub ble_DeviceNotFound
    Log("ble_DeviceNotFound")
End Sub

Private Sub ble_DeviceConnected
    Log("ble.IsConnected=" & ble.IsConnected)
End Sub
#End Region

Public Sub DestroyConnection
    If bt.IsConnected Then
        bt.DestroyConnection
    else if ble.IsConnected Then
        ble.DestroyConnection
    End If
End Sub
 
Upvote 0
Top