-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: scan not returning devices #1210
Comments
I am facing same any solution? |
any solution? |
Just to add some more info on our particular setup... AndroidManifest.xml
Our implementation is prompting the user to grant ACCESS_FINE_LOCATION, BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions. Even after these are granted, the scan doesn't do anything; no callback is fired for either device or error handlers, and unless a manual timeout is implemented, the scan continues running indeterminately. I have had one or two instances where the BLE state is returned as |
Hi, I've tried to reproduce this issue on android v12/13 and I couldn't do it. Can you share the code snippets?
|
I have used exactly the same code that is in the example! Device = nokia 5.4 android 12 I called this function from "example" in repo startConnectAndDiscover() It is using await bleservice.scanDevices and there is just a console "scanning" in it I just see that console in terminal Nothing else happens! Copied all the code from example Using the same Bluetooth service that is on the example |
Here's some example code:
I have tried running this in various modes and setting the |
Hi @chris-goodchild |
@intent-kacper-cyranowski sure, so we're using this library in the context of a very large RN app. The scan/connect/write operations are being used to install a custom BLE device. It's integrated within a set of screens guiding a user through connection. I have a
and inside the
A coworker has gottent the example app working and producing scan results. For whatever reason though, when it's integrated into the app on Android it never returns any scan results. I'm on version 3.2.0 - I have double checked that our manifest has the exact same permissions setup as the example app and as far as I can see all of our implementation code is as it should be. The app requests permissions when needed. The scan starts but it never responds with anything. I'm a bit stumped at this point. I can't share our codebase unfortunately because it's private. Do you have any idea why there would be no response at all? Could this be something related to permissions that I may have missed? Some logcat output:
|
Just to add, on the Samsung device I'm testing, if I initially have bluetooth turned off then the state is |
I have created a branch with minimal repro so we could be on the same page with the code #1210_android_scan_not_returning_devices. In my opinion to solve the problem I would need the insight to the React context. I believe that isn’t the problem with library/permissions, but with React/js code itself. I can spot some issues, but not why |
@intent-kacper-cyranowski thanks for putting the effort in to do that! I checked and really, the React Context aspect isn't a factor. It is initialised at the start of a flow of screens and only gets killed when navigated away from the stack, i.e. completing or cancelling. I tested it without using Context just to be sure but the outcome is the same. As this works fine on iOS I don't believe it's likely to be a problem at the React level, though I took some of your commented suggestions on board, thanks. A colleague has been doing some debugging and is able to see scan results using the example app after upgrading his dev environment (we needed to upgrade node/java/Android Studio), but integrating the source into our project it seems that even though scan results are there at the native layer, for whatever reason they're not being surfaced to RN. It's as if the event isn't being fired/picked up. We're still digging into it. I'll report back if we find anything. |
Just an update on this, I believe our issue may have been related to permissions and how we were linking the library. I can't be sure as it suddenly started working after numerous attempts to clean and rebuild. Our project is very large and we still manually link some libraries (because reasons). At the moment, using the example for initializing BLE, i.e. the bluetooth state subscription, the |
Looking at the code, the only case for receiving Showing relevant code or some Logcat logs after setting setLogLevel to |
Hi @chris-goodchild |
I'm having similar issues. Please don't close this issue, I will report back with any findings or fixes I have. Thanks |
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 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. |
Prerequisites
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.
The text was updated successfully, but these errors were encountered: