public interface RxBleDevice
| Modifier and Type | Method and Description |
|---|---|
<any> |
establishConnection(boolean autoConnect)
Establishes connection with a given BLE device.
|
<any> |
establishConnection(boolean autoConnect,
Timeout operationTimeout)
Establishes connection with a given BLE device.
|
android.bluetooth.BluetoothDevice |
getBluetoothDevice()
The underlying android.bluetooth.BluetoothDevice.
|
RxBleConnection.RxBleConnectionState |
getConnectionState()
Returns current connection state of the device's
BluetoothGatt |
java.lang.String |
getMacAddress()
MAC address of the corresponding device.
|
java.lang.String |
getName()
Name of the device.
|
<any> |
observeConnectionStateChanges()
Observe changes to connection state of the device's
BluetoothGatt. |
<any> observeConnectionStateChanges()
BluetoothGatt.
This Observable will never emit errors.
If you would like to have the initial state as well you can use observeConnectionStateChanges().startWith(getConnectionState())
NOTE: This is a convenience function for easy state changes monitoring of an individual peripheral that may be useful in the UI.
It is not meant to be a trigger for reconnecting a particular device—for this purpose one should react on the errors emitted from
establishConnection(boolean)RxBleConnection.RxBleConnectionState changesRxBleConnection.RxBleConnectionState getConnectionState()
BluetoothGatt<any> establishConnection(boolean autoConnect)
RxBleConnection is a handle, used to process BLE operations with a connected
device.
The connection is automatically disconnected (and released) when resulting Observable is unsubscribed. On the other hand when the connections is interrupted by the device or the system, the Observable will be unsubscribed as well following BleDisconnectedException or BleGattException emission.
During the disconnect process the library automatically handles order and requirement of device disconnect and gatt close operations.
Autoconnect concept may be misleading at first glance. In cases when the BLE device is available and it is advertising constantly you won't need to use autoconnect. Use autoconnect for connections where the BLE device is not advertising at the moment of #establishConnection call.
autoConnect - Flag related to
BluetoothDevice.connectGatt(Context, boolean, BluetoothGattCallback) autoConnect flag.
If false, the connection will fail with BleGattException if
the device is not in range after a 30-second timeout. If true, the connection will be pending indefinitely.
Unlike the native Android API, if set to true and the connection is lost there will NOT be any attempt to
reconnect unless explicitly resubscribed.BleDisconnectedException - emitted when the BLE link has been disconnected either when the connection
was already established or was in pending connection state. This occurs when the
connection was released as a part of expected behavior
(with BluetoothGatt.GATT_SUCCESS state).BleGattException - emitted when the BLE link has been interrupted as a result of an error.
The exception contains detailed explanation of the error source (type of operation) and
the code proxied from the Android system.BleGattCallbackTimeoutException - emitted when an internal timeout for connection has been reached. The operation will
timeout in direct mode (autoConnect = false) after 35 seconds.<any> establishConnection(boolean autoConnect,
Timeout operationTimeout)
RxBleConnection is a handle, used to process BLE operations with a connected
device.
The connection is automatically disconnected (and released) when resulting Observable is unsubscribed. On the other hand when the connections is interrupted by the device or the system, the Observable will be unsubscribed as well following BleDisconnectedException or BleGattException emission.
During the disconnect process the library automatically handles order and requirement of device disconnect and gatt close operations.
Autoconnect concept may be misleading at first glance. In cases when the BLE device is available and it is advertising constantly you won't need to use autoconnect. Use autoconnect for connections where the BLE device is not advertising at the moment of #establishConnection call.
autoConnect - Flag related to
BluetoothDevice.connectGatt(Context, boolean, BluetoothGattCallback)
autoConnect flag.
If false, the connection will fail with BleGattException if
the device is not in range after a 30-second timeout. If true, the connection will be pending indefinitely.
Unlike the native Android API, if set to true and the connection is lost there will NOT be any attempt to
reconnect unless explicitly resubscribed.operationTimeout - Timeout configuration for operations scheduled using RxBleConnection emitted from this observable.
Those operations will be considered broken after the specified timeout. Keep in mind that after the timeout
those operations will be canceled and may leave Android's BLE stack in an inconsistent state.BleDisconnectedException - emitted when the BLE link has been disconnected either when the connection
was already established or was in pending connection state. This occurs when the
connection was released as a part of expected behavior
(with BluetoothGatt.GATT_SUCCESS state).BleGattException - emitted when the BLE link has been interrupted as a result of an error.
The exception contains detailed explanation of the error source (type of operation) and
the code proxied from the Android system.BleGattCallbackTimeoutException - emitted when an internal timeout for connection has been reached. The operation will
timeout in direct mode (autoConnect = false) after 35 seconds.BleAlreadyConnectedException - Error emitted when the connection to a specified device is already established or is being
established. In order to share the connection, share #establishConnection emissions.java.lang.String getName()
java.lang.String getMacAddress()
android.bluetooth.BluetoothDevice getBluetoothDevice()