Scan for devices with phone screen off (Android)
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?
Hi! Thanks for the question. We will investigate and get back to you soon.
I can confirm this problem.
Hi @Microwave-WYB, @hnrgtk. We are still working on this and some other issues, so please hold on a bit longer.
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?
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:
- 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]
-
react-native-background-actionslike @hnrgtk mentioned - 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