dotintent / react-native-ble-plx

React Native BLE library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All devices is not discoverable in Android 14πŸ›

pariharkaran opened this issue Β· comments

Prerequisites

  • I checked the documentation and FAQ without finding a solution
  • I checked to make sure that this issue has not already been filed

Expected Behavior

BLE PLX should successfully discover Bluetooth devices, including the last connected device.

Current Behavior

When i scan and try to connect with device then device is connected successfully first time. But when close and reopen app then call startDeviceScan method then last connected device is not discovering.
Also when i turn off and then on bluetooth from notification panel then suddenly that bluetooth device is discovered.

Library version

3.1.2

Device

Pixel 7

Environment info

OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1
    Memory: 607.06 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.0.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
    Watchman: 2023.08.28.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/varshid-innvonix/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
    Android SDK:
      API Levels: 21, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 33, 34
      Build Tools: 27.0.3, 28.0.2, 28.0.3, 29.0.0, 29.0.2, 29.0.3, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0, 33.0.1, 33.0.2, 34.0.0, 35.0.0
      System Images: android-30 | Google Play ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-32 | Google APIs ARM 64 v8a, android-32 | Google Play ARM 64 v8a, android-33 | Google APIs ARM 64 v8a, android-33 | Google Play ARM 64 v8a, android-34 | Google Play ARM 64 v8a
      Android NDK: 22.1.7171670
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9619390
    Xcode: 15.0/15A240d - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.9 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^16.14.0 => 16.14.0 
    react-native: ^0.66.5 => 0.66.5 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Scan and Connect with device
  2. close and reopen app
  3. Scan for device

Formatted code sample or link to a repository

manager.startDeviceScan(null, null, (error, device) => { 
    if (error) { 
      // Handle error (scanning will be stopped automatically) 
      return 
    } 

    if (device.name === "MyDevice") { 
      connect() 
      manager.stopDeviceScan() 
      // Proceed with connection. 
    } 
  })

Relevant log output

All devices found except last connected one.

Additional information

No response

Hi @pariharkaran,
Thank you for reaching out. We'll analyze the issue and get back to you as soon as we can.

What does "close and reopen" mean? Are you sure the device was disconnected, before you tried to find it again?

Hi @pariharkaran
I think that your problem is abrupt closing of app and not closing the connection between devices. The library by itself does not handle such scenerio. If you close the connection on the second device they should be again discoverable.

Let me know if it solves your problem

I found the solution from Android's official docs.
I need to change the DEFAULT_SCAN_MODE from Native Modules in startDeviceScan() inside BlePlxModule.java file.
so please replace value of DEFAULT_SCAN_MODE_LOW_POWER with 2, this is recommended when app is in foreground.
Android document link

I'm glad that you manage to solve the issue on your own and thanks for describing how you did so.
As for the suggestion we probably won't change the default scan mode as it may affect other users, but we might add the ability for the user to change it from javascript.