Handling background camera restrictions for continuous posture monitoring in Android

6 days ago 7
ARTICLE AD BOX

I’m working on a project that does real-time posture monitoring. The architecture relies on taking a frame from the front camera every 3 minutes, running it through ML Kit, and updating a local score. The user starts the tracking session and can end it from the app. This feature works in the background while the user is using our app or while our app is minimized and the user is using other apps. An alert notification is sent after every check if the user is in a bad pose. We thought we could work it around by showing a notification stating Posture tracking in progress.

The Roadblock:

I am hitting the strict Android 14 (API 34+) while-in-use permission restrictions. As the documentation states, if the app is in the background and tries to create a foreground service of type camera, it throws a SecurityException. Furthermore, keeping the camera connection alive while the app is fully backgrounded (paused) seems increasingly hostile on modern Android versions without highly complex, continuous Foreground Service workarounds.

My Proposed Architecture (Focus Mode):

To avoid writing a massive continuous CameraX foreground service just to snap a frame every 3 minutes, I am considering a "Wakelock" architecture.

My Question:

Is there a cleaner architectural pattern in modern Android to securely wake up, snap a frame silently, and go back to sleep without forcing the user to keep the Activity open?

Any architectural advice would be hugely appreciated!

Read Entire Article