GattClientAPI

interface GattClientAPI

Interface around native Android API. For real BLE connections it uses BluetoothGatt, whereas for mock device it utilizes MockEngine.

Properties

Link copied to clipboard
abstract val autoConnect: Boolean

Parameter obtained from BleGattConnectOptions.autoConnect created during connection.

Link copied to clipboard

Parameter indicating that Gatt should be closed on first disconnected event.

Link copied to clipboard
abstract val device: ServerDevice

A server device which has been used to establish connection. It can be either mock or real BLE server device.

Link copied to clipboard
abstract val event: SharedFlow<ClientGattEvent>

Flow which emits BLE events. For real BLE connections it collects events from BluetoothGattCallback under the hood, for mock device it gets events from MockEngine.

Functions

Link copied to clipboard
abstract fun abortReliableWrite()

Aborts reliable write. All writes to a characteristics which supports reliable writes will be reverted to a state preceding call to beginReliableWrite.

Link copied to clipboard
abstract fun beginReliableWrite(): Boolean

Begins reliable write. All writes to a characteristics which supports this feature will be transactional which means that they can be reverted in case of data inconsistency.

Link copied to clipboard
abstract fun clearServicesCache()

Clears services cache. It should invoke BluetoothGattCallback.onServiceChanged callback.

Link copied to clipboard
abstract fun close()

Releases connection resources. It should be called after disconnect succeeds.

Link copied to clipboard

Disables notifications on a characteristic.

Link copied to clipboard
abstract fun disconnect()

Disconnects from a peripheral.

Link copied to clipboard
abstract fun discoverServices(): Boolean

Discover services available on a remote server device.

Link copied to clipboard

Enables notifications on a characteristic.

Link copied to clipboard

Executes reliable write. All writes to a characteristics which supports reliable write will be executed and new values will be set permanently.

Link copied to clipboard

Internal function for propagating events to event shared flow. For internal usage only.

Link copied to clipboard

Reads value from a characteristic.

Link copied to clipboard

Reads value from a descriptor.

Link copied to clipboard
abstract fun readPhy()

Reads phy properties of the connection

Link copied to clipboard
abstract fun readRemoteRssi(): Boolean

Reads rssi of a remote server device.

Link copied to clipboard
abstract fun reconnect(): Boolean

Connects to a peripheral after disconnection. Works only if BleGattConnectOptions.closeOnDisconnect is set to false.

Link copied to clipboard

Requests connection priority. It will influence latency and power consumption.

Link copied to clipboard
abstract fun requestMtu(@IntRange(from = 23, to = 517) mtu: Int): Boolean

Requests mtu. Max value is 517, min 23.

Link copied to clipboard
abstract fun setPreferredPhy(txPhy: BleGattPhy, rxPhy: BleGattPhy, phyOption: PhyOption)

Sets preferred phy for the connection.

Link copied to clipboard
abstract fun writeCharacteristic(characteristic: IBluetoothGattCharacteristic, value: DataByteArray, writeType: BleWriteType): Boolean

Writes value to a characteristic.

Link copied to clipboard

Writes value to a descriptor.