Search code examples
androidcamerapreviewsurfaceviewandroid-camera

Keep camera captured by an activity after picture taken


It is necessary for my application to keep the camera captured until released manually by an Activity (I realize this is bad practice, as no other applications will be able to use the camera). I used to be able to do this by avoiding the camera.release() call in the surfaceDestroyed function from CameraPreview, but this no longer works after 2.1.

Is there any way to keep the camera in captivity, without it being automatically released after surfaceDestroyed?

As a workaround question to answer instead of the previous one, is there any way to take a picture from within a service, without the preview view inflated?


Solution

  • You may be able to call camera.lock() to re-obtain the lock on the camera hardware. Failing that you can reopen the camera.

    However, the drawback to this is much worse than preventing other apps from accessing the camera. This will also rapidly drain the battery, because it keeps the camera sensor and DSP powered. According to this thread, that could potentially kill a battery dead in two hours.