Background app on locked phone

from the CommonsWare Community archives

At December 14, 2021, 5:35pm, Jan asked:

Hi, Mark,
Is it possible to have an Android mobile phone app run entirely in the background to periodically collect data from a nearby proprietary bluetooth device? Target is SDK 31 but backwards compatible to Lollipop.

Ideally, we want to run when phone is closed and locked and without any user interaction. Due to background process limitations in Android 12, would WorkManager be a good choice for something like this?

At December 15, 2021, 12:43am, mmurphy replied:

That depends a lot on what your intended frequency is. AFAIK, you could have a Worker that tries to connect to the Bluetooth device and collect the data. And, outside of error conditions, it could remain in the background. However, WorkManager does not get you away from the limitations imposed by Doze mode, app standby, and vendor-specific battery-saving hacks.