Skip to content
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 app can not discover any device by scaning function #1206

Open
yinghuochongfire opened this issue Apr 18, 2024 · 7 comments
Open

android app can not discover any device by scaning function #1206

yinghuochongfire opened this issue Apr 18, 2024 · 7 comments

Comments

@yinghuochongfire
Copy link

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
@yinghuochongfire
Copy link
Author

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

@marcosinigaglia
Copy link
Member

So probably is a device problem.

@lucaswitch
Copy link
Contributor

lucaswitch commented Apr 24, 2024

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:

  1. Make sure bluetooth is on
  2. Make sure permissions is granted
  3. Start scan, listen to discovered devices callback.

And afterwards when scan is not running

  1. Empty discovered devices
  2. Unregister scan discovery callback.

@mohammadrajabraza
Copy link

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

@jeslo
Copy link

jeslo commented May 22, 2024

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

@theflyinhawaiian
Copy link

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.

@renochew
Copy link

renochew commented Jun 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants