0

I currently have a project on my desk which uses a 3:rd party library that deals with (BLE) device specific functionality. That means, library handles attempts to connect, enabling characteristics notifications, readings and writings.

The problem I'm having is that this library does not provide any methods for BluetoothGattCallback methods, nor is there any way to handle in app when ever a Characteristics is read/written. What I do have access to, is couple of methods where I'm able to pass my callbacks and which are triggered after some tasks.

Before my callback is triggered, the lib have behind the scenes has received numerous onCharacteristicRead calls.

In my opinion, this project should rely on when ever a BluetoothCharacteristics are triggered (by R/W/S/N), rather than triggering a callback function when a set of instructions or rules are completed within that 3:rd library.

For example, one can retrieve connect(ed) device(es) from BluetoothManager as follows (1's are just dummies):

// Initializes a Bluetooth adapter.  For API level 18 and above, get a reference to
// BluetoothAdapter through BluetoothManager.
final BluetoothManager bluetoothManager = 
           (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothDevice device = 
           bluetoothManager.getConnectedDevices(1).get(1);

but to retrieve gattcallback is nowhere to be found.

The device I have can only manage 1 active connection, so I'm wondering if there are any ways or workarounds ?

As a side note, "nRF Connect" app does this somehow. When leaving it open in background, new device tab is opened when i establish connection from my App with the BLE device.

Deko
  • 1,028
  • 2
  • 15
  • 24
  • 1
    Just use connectGatt and you will get another logical connection to the same physical connection. – Emil Mar 23 '17 at 08:51
  • I just realised the BluetoothLeGatt Example from Android sources, behaves exactly as I need. Good to know "no new connection" is initiated even tho calling connectGatt. My bad for not reading docs enough. – Deko Mar 23 '17 at 08:59

0 Answers0