private Camera mCamera; private CameraPreview mPreview; // Get camera instance mCamera = Camera.open(); // Create a CameraPreview and set it as the content of the activity. mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); preview.addView(mPreview); // Start the camera preview mCamera.startPreview();
// Get camera instance mCamera = Camera.open(); // Set camera parameters Camera.Parameters parameters = mCamera.getParameters(); // Set flash mode parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); // Set focus mode parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); // Set picture size parameters.setPictureSize(1920, 1080); // Apply the parameters to the camera mCamera.setParameters(parameters); // Start the camera preview mCamera.startPreview();This code sets up the camera parameters like flash, focus, and picture size before starting the camera preview. Package library: android.hardware.Camera