react-native-ble-manager
react-native-ble-manager copied to clipboard
[Android] Peripheral not found when retrieving Services
Version
Tell us which versions you are using:
- react-native-ble-manager v6.6.8
- react-native v59.8
- iOS/Android Android v.25
Expected behaviour
Should return peripheralInfo, as it always did, and still does on iOS.
Actual behaviour
Returns "Peripheral not found"
Steps to reproduce
- Connect to device
- Call retrieveServices
Stack trace and console log
I debugged already the Android code, but can't find the reason, why it is not working. The peripherals Map<> is always empty. When a peripheral gets discovered, it is added to the peripherals Map. But when retrieveServices() gets invoked, the Map is always empty. Can someone reproduce the issue?
Maybe is something related to this commit . Do you use the forceLegacy
flag?
I agree, it is probably related to the commit. Are you able to reproduce? No I don't use the forceLegacy flag.
No, I tested on different Android with no problem.
forceLegacy doesn't fix the problem.
Unfortunately I'm not experienced enough with the Android Platform to track the root cause down. I downgraded to Version 6.6.5, which solved the problem for me.
I'm having the same issue on a Galaxy Note 9 running Android 9. My previous app version was using React Native 0.56 and react-native-ble-manager 6.6.2 and it was working. Since I updated to React Native 0.60 it's not working anymore even with 6.6.2 or 6.6.8. I'm going to do some checks hope to help.
@BaloMueller I found the root cause for my case.
I was calling startScan at every scan stop event if no devices was already connected.
The problem was that the setState I was calling right after the connection was not fast enough to prevent the startScan to be called again.
As I can see from the native code the "peripherals" map will be empty whenever a new scan starts
I think is better to use the BleManagerDiscoverPeripheral event to save the peripherals in your app.
I think is better to use the BleManagerDiscoverPeripheral event to save the peripherals in your app.
I'm using it. But I'm scanning and searching for a specific device. If I don't find it I need to rescan.
@BaloMueller I found the root cause for my case. I was calling startScan at every scan stop event if no devices was already connected. The problem was that the setState I was calling right after the connection was not fast enough to prevent the startScan to be called again. As I can see from the native code the "peripherals" map will be empty whenever a new scan starts
Thank you so much for this, this just really helped us out. This should be in the documentation of the scan or retrieveServices function, as many people are likely performing continuously looping scans which will cause problems here.