Skip to content

FAQ: Cannot connect

Dariusz Seweryn edited this page Jun 18, 2018 · 7 revisions

Known Android BLE Stack peculiarities

This library aims for removing as much of Android related issues as possible so the user will not have to think about them. Unfortunately this is not always possible without a handicap on usefulness or aggressive actions to ensure proper behaviour.

Connect without a scan

Direct connect to a peripheral (RxBleDevice.establishConnection(autoConnect = false)) may not succeed until it will be scanned. The problem is that the Android OS exposes a 48 bit MAC address identifier which does not contain information about the address type (public/random/etc.). This information is contained by the internal Android BLE stack which is cleared once the BluetoothAdapter is turned off. After this clear if you try to connect to your peripheral the Android makes a guess under the hood to figure out the type address. If the guess will not be correct then a connection will not succeed until the device will get re-scanned. (source)

  • To mitigate the problem you should track the changes in the BluetoothAdapter's state and always scan your peripheral before connecting (whether you know that adapter was turned off or do not know it was turned off).

Connect while scanning

Some Android devices (i.e. Huawei, Asus) are reportedly not handling well connecting to a peripheral if there is an ongoing BLE scan.

  • To have a solution that works on most of the devices out there you must first stop the scan before you start to connect to a peripheral.