stuck on connecting on Huawei device trying to connect to BLE device
See original GitHub issueim trying to connect to different BLE devices from a Huawei P9 lite
but it gets stuck in connecting state in most of the times. if i clear bluetooth share
system application’s cache, connection will be successful for the first time sometimes but it will again get stuck to connecting state after trying to reconnect.
steps to reproduce:
1- try to connect to a ble device from Huawei P9 lite
(its probably unsuccessful in first try but if its not go on)
2- turn off BLE device or turn off mobile bluetooth
3- try to reconnect and it gets stuck in connecting and nothing else happens.
my code snippet is:
rxBleClient
.scanBleDevices(getSettings(), getFilter())
.timeout(SCAN_TIMEOUT, TimeUnit.MILLISECONDS, Observable.empty())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onNext = { scanResult ->
device = scanResult.bleDevice
Timber.i("Found $device")
},
onError = { throwable ->
Timber.e(throwable)
},
onComplete = {
device?.let {
startConnecting(it)
}
?: Toast.makeText(context, "No device found!", Toast.LENGTH_LONG).show()
})
start connecting method:
private fun startConnecting(device: RxBleDevice) {
Timber.i("connecting to $device")
mayDisconnect()
connectionStateDisposable = device.observeConnectionStateChanges()
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onNext = { connectionState: RxBleConnection.RxBleConnectionState ->
when (connectionState) {
RxBleConnection.RxBleConnectionState.CONNECTING -> Timber.i("connecting...")
RxBleConnection.RxBleConnectionState.CONNECTED -> Timber.i("connected!")
RxBleConnection.RxBleConnectionState.DISCONNECTING -> Timber.i("disconnecting...")
RxBleConnection.RxBleConnectionState.DISCONNECTED -> Timber.i("disconnected!!!")
}
},
onError = { throwable ->
Timber.w(throwable)
},
onComplete = {
Timber.i("state change complete!")
})
connectionDisposable = device.establishConnection(true)
.subscribeBy(
onNext = { bleConnection ->
this@MainActivity.bleConnection = bleConnection
requestMTU()
readCounter()
registerCounter()
},
onError = { throwable ->
Timber.e(throwable, "Device disconnected: ${device.name}(${device.macAddress})")
},
onComplete = {
Timber.i("connection complete!")
})
}
the log is:
I/RxBle#QueueOperation: Scan operation is requested to start.
I/BluetoothAdapter: getBluetoothLeScanner
I/MainActivity$startScan(MainActivity.kt:152): Found RxBleDeviceImpl{bluetoothDevice=Things(62:B2:C6:E2:00:6E)}
I/RxBle#CancellableDisposable: Scan operation is requested to stop.
I/BluetoothAdapter: getBluetoothLeScanner
I/MainActivity(MainActivity.kt:183): connecting to RxBleDeviceImpl{bluetoothDevice=Things(62:B2:C6:E2:00:6E)}
I/MainActivity$startConnecting(MainActivity.kt:192): connecting...
expected: it should connect after finding the device and calling establishConnection method.
actual: it gets stuck in connecting state
android app repo: https://github.com/mohsenoid/android-things-ble-sample-app
android things gat repo: https://github.com/mohsenoid/android-things-ble-sample
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (7 by maintainers)
Top GitHub Comments
Hello,
Thank you for using the library. Your post seems to be a bug report but it lacks some crucial information. Could you edit to contain information according to the issue template?
Best Regards
Hey @amirziarati, did you find a solution since then ? Having some BLE problems with Huawei smartphones…