The code below is my Android Camera API implementation, and as you can see i commented out the button/onClickListener bit. This results in the error 'takePicture Failed' during runtime. But when I use the button (and really nothing else) it works fine. (shows preview, button works, image is saved to where I want it). However I would really like to do this without a button (take picture as soon as the activity is launched). What's going wrong here?
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_front_camera);
    if(checkCameraHardware(this)) {
        mCamera = getCameraInstance();
        mPreview = new CameraPreview(this, mCamera);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
        preview.addView(mPreview);
        mCamera.takePicture(null, null, mPicture);
        mCamera.release();
        // Add a listener to the Capture button
        /*Button captureButton = (Button) findViewById(R.id.button_capture);
        captureButton.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // get an image from the camera
                    mCamera.takePicture(null, null, mPicture);
                    mCamera.release();
                }
            }
        );
        */
        //mCamera.takePicture(null, null, mPicture);
        //mCamera.release();
    }
}
 
    