question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

stuck on connecting on Huawei device trying to connect to BLE device

See original GitHub issue

im 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:closed
  • Created 5 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, Oct 2, 2018

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

0reactions
g-balascommented, Dec 17, 2020

Hey @amirziarati, did you find a solution since then ? Having some BLE problems with Huawei smartphones…

Read more comments on GitHub >

github_iconTop Results From Across the Web

stuck on connecting on Huawei device trying to ... - GitHub
im trying to connect to different BLE devices from a Huawei P9 lite but it gets stuck in connecting state in most of...
Read more >
Easy Steps to Fix Bluetooth Connecting Problem
Reboot your phone, then turn on/off Bluetooth;. Search Reset network settings in Settings, tap RESET NETWORK SETTINGS and then turn on/off Bluetooth;. *Reminder ......
Read more >
How to fix Huawei P30 Bluetooth connection problems
Huawei P30 Bluetooth connection problems fix #7: Wipe cache partition · With your phone turned off, press and hold both the Volume Up...
Read more >
How to Fix Bluetooth Pairing Problems - Techlicious
Can't connect two devices? Try these 16 tips to solve your Bluetooth pairing problems.
Read more >
How to FIX Bluetooth on Android Phone that FAILS to Connect ...
Hi, this video shows you a simple FIX to get your Bluetooth working again on your Android mobile cell phone. It also shows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found