react-native-ble-plx icon indicating copy to clipboard operation
react-native-ble-plx copied to clipboard

Scan for devices with phone screen off (Android)

Open hnrgtk opened this issue 1 year ago • 3 comments

Prerequisites

  • [X] I checked the documentation and FAQ without finding a solution
  • [X] I checked to make sure that this issue has not already been filed
  • [X] I'm sure that question is related to the library itself and not Bluetooth Low Energy or Classic in general. If that so, please post your question on StackOverflow.
  • [X] I'm running the latest version

Question

My app scan for devices and gets advertisings from previously connected devices. I installed react-native-background-actions lib and it works when the app is not in the foreground but stops scanning when the screen is off. Is there any way to make the scan keep working?

hnrgtk avatar Feb 18 '24 23:02 hnrgtk

Hi! Thanks for the question. We will investigate and get back to you soon.

EmmaZachara avatar Feb 21 '24 13:02 EmmaZachara

I can confirm this problem.

Microwave-WYB avatar Mar 15 '24 22:03 Microwave-WYB

Hi @Microwave-WYB, @hnrgtk. We are still working on this and some other issues, so please hold on a bit longer.

EmmaZachara avatar Apr 19 '24 09:04 EmmaZachara

Hello, I have the same problem. Is there a way to ensure that the library can perform ble scans even if the screen is off?

Beckmann0o avatar Oct 28 '24 17:10 Beckmann0o

Hello.

Scanning for BLE when the screen is off on Android devices can be challenging due to system limitations and power management policies. To enhance the likelihood of successful background scanning, consider the following steps:

  1. According to the documentation of the native library that we use for bluetooth connection on android you should add
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="30" />

in AndroidManifext.xml to be able to scan in the background. [LINK]

  1. react-native-background-actions like @hnrgtk mentioned
  2. Some device manufacturers implement aggessive power-saving measures that may affect background operations. It may need to be adjusted in the device settings.

Please let me know if that helped

aliberski avatar Jan 09 '25 19:01 aliberski