This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BLE App background connection

Hi,

My devices are currently using NRF52832 with SDK17.0.0.

I want to communicate with my devices even when the app is killed by the Android system.

At this moment, when I close the phone after some time, the connection no longer exist.

Thanks.

  • Hi, 

    There's something called background service limitations in Android 8+.  Service needs to be promoted to foreground service, which displays a notification, to not be killed after 5 min. 

    However, there's a new API in Bluetooth Le Scanner which allows to scan using PendingIntent. So you may register in the system that your app should be awakened when some device is found. And connect to it, in foreground service if the constant connection is needed. This scan with pending intent can be started, as you said, on broadcast receiver for this event. When using Scanner Compat library for Android it will try to emulate this pending intent on earlier os versions. Using the background scanner, this will of course use much more battery. So it can be done efficiently on Android 8+.  You can search on the internet about Bluetooth Le Scanner. 

    The support staff is reduced during the summer holidays, and you may experience delayed answers.

Related