public class BLEErrorResolver
extends java.lang.Object
Here's how I do it:
Call bluetoothle.isConnected(). If isConnected == false (i.e., connection exists but is inactive), run bluetoothle.disconnect(). Repeat bluetoothle.disconnect() call until connection is definitely disconnected (I.e., repeat disconnect() at 200ms interval until disconnectError executes. In disconnectError, call bluetoothle.close(). Repeat bluetoothle.close() every 200ms until closeError executes. In closeError, set a timeOut of 2000ms, then call bluetoothle.connect(). Allow 10000ms for connect() to succeed before proceeding with discover(), subscribe() and write(). If connect() times out, return to first step with bluetoothle.isConnected(). When finished transaction, call disconnect() and close() - again, repeating each until they've definitely completed. When I do it this way, it seems to work first time most of the time, and never takes more than about 3 reattempts of connect().
On Android 4.x and iOS, I still leave the connection present and use bluetoothle.reconnect() if isConnected == false, and it works fine.
Constructor and Description |
---|
BLEErrorResolver() |
Modifier and Type | Method and Description |
---|---|
io.reactivex.Observable<java.lang.Object> |
resolve(BLEPeripheral peripheral) |
io.reactivex.Observable<java.lang.Boolean> |
toggleAdapter(android.bluetooth.BluetoothAdapter mBluetoothAdapter,
boolean enabled,
int maxRetry) |
public io.reactivex.Observable<java.lang.Object> resolve(BLEPeripheral peripheral)
peripheral
- public io.reactivex.Observable<java.lang.Boolean> toggleAdapter(android.bluetooth.BluetoothAdapter mBluetoothAdapter, boolean enabled, int maxRetry)