I am currently working on an Android app which should read sensor values from a bluetooth periperal and send them to a backend server. To enable this app to work when the screen is turned off, a partial wake lock is acquired and the app is put on the battery optimization whitelist by the user. I know that the battery whitelist should only be used when no other option is available, but for my use case, it seems to be the only solution, as described on the table at the end of this article: https://developer.android.com/training/monitoring-device-state/doze-standby. The table states that the whitelist is an acceptable solution for an app, when "App's core function is maintaining a persistent connection with the peripheral device for the purpose of providing the peripheral device internet access."
This exactly describes my use case.
However, when i debug the application, i can see that the wake-lock is taking effect, because the app is not suspended when the screen turns off and the bluetooth API is still receiving notifications. However, after a view minutes, the wifi stops working, resulting in all requests remaining in the "pending" state. This also happens when using the mobile network instead of wifi. I already tried buffering the received data until the network is available again, however i dont consider this a valid solution since the app may run out of memory before the user is unlocking his device again.
I have read that in android version previous to android 7, apps could use a wifi lock to keep the wifi working for that specific application. Is there a similar feature in android version 8 or 9? Or is there a configuration options in the devices settings that i missed to keep the wifi awake?
Since the use case is described in the android developer article, is suggest that somebody did already implement an app that does the exact same thing. Is there a code example available that demonstrates how this can be accomplished?
My mobile app is implemented using cordova. I tried the following plugins to keep my app awake:
for the wake lock: cordova-plugin-powermanagement: 1.0.5 or higher.
to prompt the user to put the app on the whitelist: cordova-plugin-doze-optimize: 0.5.4 or higher.