react-native-ble-manager
react-native-ble-manager copied to clipboard
android app can not discover any device by scaning function
Describe the bug in most case,android app can work well. but, sometimes, android app can not discover any device by scaning device. when i try to restart my phone, and run the app again, the app works well again, it can discover device quickly. scan device.txt
when i exit my app and restart my app again,This situation is often repeated.
Smartphone (please complete the following information):
- Device: honor
- OS: magic OS 7.2
- react-native-ble-manager version: 11.0.6
- react-native version:0.73.0
now ,i find a new case. When I manually enable Bluetooth on my phone before the APP runs, the APP does not return any device when scanning Bluetooth devices. But when the APP run before, I manually disable my phone bluetooth,and when the APP runs, through the code "BleManager. EnableBluetooth ()" enable the bluetooth, and then scan, can return devices. Repeat many times, the phenomenon is the same
So probably is a device problem.
Don't think it's a library bug. But quick looking at your implementation i could notice something. Make sure to register the events callback when the bluetooth is turned on, permission ready and when callbacks needed, make sure to unregistering it when it's not needed anymore.
For that scanning you should do:
- Make sure bluetooth is on
- Make sure permissions is granted
- Start scan, listen to discovered devices callback.
And afterwards when scan is not running
- Empty discovered devices
- Unregister scan discovery callback.
I began with the example provided in the library and encountered a similar problem as @yinghuochongfire . The scan function doesn't seem to work until I attempt it with companionScan. Once a device is discovered, I can close the app and then try scan again, and it works.
Smartphone (please complete the following information):
Device: MI 10T react-native-ble-manager version: 11.5.3 react-native version:0.73.2
I have a related issue in Android. When launching the app, it asks for permission, and I grant it, but the scan is not working. I checked the phone settings, and the permissions are granted. When I toggle the permission off and then on again from my physical device's settings, the scan works perfectly. So, the permission needs to be granted from the physical device settings.
Device: MI 11X react-native-ble-manager version: 11.5.3 react-native version:0.74.1
I began with the example provided in the library and encountered a similar problem as @yinghuochongfire . The scan function doesn't seem to work until I attempt it with companionScan. Once a device is discovered, I can close the app and then try scan again, and it works.
Smartphone (please complete the following information):
Device: MI 10T react-native-ble-manager version: 11.5.3 react-native version:0.73.2
Thank you for this!!
You'll also need to add:
<uses-feature android:name="android.software.companion_device_setup"/>
to your manifest if you haven't, in order to get companionScan to run.
Just want to chime in the exact situation as described by @yinghuochongfire happen to me today. I scratched my head all day as handleDiscoverPeripheral just can't catch any result from a scan, no matter what I tried, but once I did a successful companion search, subsequent scan will be magically successful.
And I can't even reproduce the original problem anymore, as if the device can't "unseen" the device. It might be a good idea to test it with another phone, but I don't have one at the moment. I don't think the original problem is solved, something still not right before we did the companion search.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.