PreviewCallback and PreviewCallback with buffer are not called

android, callback, camera

Solution

You must to call setPreviewCallback in surfaceChanged method, not only in surfaceCreated.

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    if (mHolder.getSurface() == null){
      return;
    }

    try {
        mCamera.stopPreview();
    } catch (Exception e){
      // ignore: tried to stop a non-existent preview
    }

    try {
        mCamera.setPreviewCallback(this);
        mCamera.setPreviewDisplay(mHolder);
        mCamera.startPreview();

    } catch (Exception e){
        Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
}

Problem

I have a question regarding the preview callbacks with Android 4.0.x. I set up a camera, create a surface to display camera image `on previewCallback`-event. Everything works fine. But with Android 4.0.x neither `onPreviewCallback` is called nor `onPreviewCallbackWithBuffer`. Is there a workaround for this issue? I want to take a screen shot and do not want to use the `takePicture()`-way because it freezes the live image for a short-time.

Original source