Code example for Camera

Methods: autoFocusgetParameterssetPreviewDisplaystartPreview

0
    } 
 
    public void surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, now tell the camera where to draw the preview. 
        try { 
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
            tryAutoFocus(); 
            Log.d("CameraPreview","surfaceCreated");
        } catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        } 
    } 
 
    public void surfaceDestroyed(SurfaceHolder holder) {
        // empty. Take care of releasing the Camera preview in your activity. 
    	 
    } 
 
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        // If your preview can change or rotate, take care of those events here. 
        // Make sure to stop the preview before resizing or reformatting it. 
 
        if (mHolder.getSurface() == null){
          // preview surface does not exist 
          return; 
        } 
 
        // stop preview before making changes 
        try { 
            mCamera.stopPreview();
        } catch (Exception e){
          // ignore: tried to stop a non-existent preview 
        } 
        // start preview with new settings 
        try { 
            mCamera.setPreviewDisplay(mHolder);
            mCamera.startPreview();
            //tryAutoFocus(); 
 
        } catch (Exception e){
            Log.d(TAG, "Error starting camera preview: " + e.getMessage());
        } 
    } 
     
    // Attempt to activate auto focus 
    private void tryAutoFocus(){ 
    	if(mCamera.getParameters().getFocusMode().compareTo("FOCUS_MODE_AUTO") == 0 ||  
    			mCamera.getParameters().getFocusMode().compareTo("FOCUS_MODE_MACRO") == 0){
    		Log.d(TAG,"Setting autofocus");
    		mCamera.autoFocus(null);
    	} 
    } 
     
    // Restart camera preview between shots 
    public void restartPreview(){