Android: onPreviewFrame never called without SurfaceView

android, camera, preview, surfaceview

Solution

According to this question, creating a `SurfaceView` in code works fine. Though I don't think you can create it through a service.

Another approach is to create a 1px-1px `SurfaceView` inside a `RelativeLayout` and hiding it with some other view on top of it. (visibility should still be `VISIBLE`). We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine.

Problem

On some devices, `onPreviewFrame` is not called if no `SurfaceView` was set to display the camera preview. However, I handle the camera in a service, so I can't set a `SurfaceView` but I don't want to have visible preview anyway. How can this be done? Can I programmatically create a `SurfaceView` and set it with `Camera::setPreviewDisplay`? This must be possible or not? It works on almost every phone without a `SurfaceView` but not on HTC One X and Google Nexus One...

Original source

Related problems