A couple of things I noticed.
First, when camOn == false
you have cam.release()
even though cam=Null
at that point. If I'm missing something there, that's fine.
The second is that you actually need a surfaceView
element to use the camera. Some devices are OK without that, but it is part of the android system, as detailed here.
For example, after adding a surfaceView to your layout, you would do
msurfaceView = (SurfaceView)findViewById(R.id.surfaceView);
msurfaceHolder = surfaceView.getHolder();
msurfaceHolder.addCallback(this);
msurfaceHolder.setFixedSize(1, 1);
and after setting the parameters for the camera with setParameters
, call
mCamera.setPreviewDisplay(mSurfaceHolder);
mCamera.startPreview();
This was an issue on one of my phones, and using the surface view solved that. I assuming you've edited the manifest file to include the right permissions.