Reputation: 21
I am creating an application (with camera2 api) that recording a long videos when the application is on the background (onStop state), At first it works fine but after some time (around 10 mins) the camera freezes and getting onError callback with error value 3. when the application is not on the background it works just fine. any idea how I can fix it?
Upvotes: 1
Views: 1251
Reputation: 18117
Error value 3 is ERROR_CAMERA_DISABLED.
The latest versions of Android do not allow camera access while in the background. There's a short delay before enforcement happens when your app goes into the background, but eventually you'll be disconnected and receive that error code.
To keep the camera open, you need a foreground service at the minimum, which means you have to have a notification running for your service, to inform users that your app is actively doing something.
Upvotes: 2