react-native-ble-plx: Android: scan not returning devices

Prerequisites

  • I checked the documentation and FAQ without finding a solution
  • I checked to make sure that this issue has not already been filed
  • I’m sure that question is related to the library itself and not Bluetooth Low Energy or Classic in general. If that so, please post your question on StackOverflow.
  • I’m running the latest version

Question

I am experiencing an issue on Android (tested on OS v12/13) with React Native 0.70.14 - I am running the latest version of react-native-ble-plx

From my logs, I can see that bluetooth is successfully initialized (although initially it always reports PoweredOff, for some reason). Subsequently, I am prompting the user to grant the following permissions:

  • PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
  • PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT
  • PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN

I have confirmed that location fine access is also granted, as are these permissions, but when it comes to the BLE scan I’m not getting any results. The BLE device is in pairing mode, I get no errors or results during the scan. On iOS this all works without issue, it’s only on Android.

AndroidManifest.xml contains all of the required permissions as per the documentation and these permissions are confirmed to be granted prior to running the scan. I’m just not sure why the scan is providing no feedback at all. I’ve reviewed suggestions from other issues but none appear to be applicable here. Do you have any pointers as to what this issue might be? I’m happy to provide further details if needed.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (1 by maintainers)

Most upvoted comments

Apologies for the (very) late reply @intent-kacper-cyranowski . Yes, we’re still seeing the issue intermittently. Also seeing frequent disconnects on both iOS and Android. On Android specifically, sometimes we get results but about half the time we get nothing at all. In general, if we do manage to find the device and connect to it, the connection is super unstable. It seems like reconnect attempts sometimes work but in most cases (again, both platforms) everything needs to be destroyed and started again. It’s super hard to see what’s going on though. I’m not sure if the isDeviceConnected method is particularly reliable either. Before writing a characteristic I check the connection status using this method and it returns true, but then the attempted write results in a combination of cancelled and disconnected errors. It’s as if the ble-plx library gets out of sync with the actual device connection or something.

We have been testing our BLE device using other bluetooth apps and it’s only ble-plx that seems to have this issue. In all other tests the connection is persistent but in the app using ble-plx the connection drops frequently.

So glad to have found someone else that is having the same issues. Android often not seeing devices despite being visible in the OS device list, super unstable connections especially on android, isConnected returning true even though it’s not. Really frustrating both for our developers and for our customers.

Apologies for the (very) late reply @intent-kacper-cyranowski . Yes, we’re still seeing the issue intermittently. Also seeing frequent disconnects on both iOS and Android. On Android specifically, sometimes we get results but about half the time we get nothing at all. In general, if we do manage to find the device and connect to it, the connection is super unstable. It seems like reconnect attempts sometimes work but in most cases (again, both platforms) everything needs to be destroyed and started again. It’s super hard to see what’s going on though. I’m not sure if the isDeviceConnected method is particularly reliable either. Before writing a characteristic I check the connection status using this method and it returns true, but then the attempted write results in a combination of cancelled and disconnected errors. It’s as if the ble-plx library gets out of sync with the actual device connection or something.

We have been testing our BLE device using other bluetooth apps and it’s only ble-plx that seems to have this issue. In all other tests the connection is persistent but in the app using ble-plx the connection drops frequently.

Looking at the code, the only case for receiving OperationCancelled on manager.enable is to cancel subscription manually or by creating new instance of BleManager (in effect of that it could drop subscription).

Showing relevant code or some Logcat logs after setting setLogLevel to LogLevel.Verbose, and filtering them with package:mine (tag:BluetoothGatt | tag:ReactNativeJS | RxBle) should provide more insight to the problem