Chris Rock Chris Rock - 10 months ago 69
Android Question

Make Flash always ON(CameraPreview Android)

I just started to develop an Android app that needs to use camera features in order to capture images and I want to keep the Flash ALWAYS ON. The problem is that when I start the camera from app the flash only blinks once and stops.

I implemented the camera with Camera class and I used the CameraPreview that extends SurfaceView and implements SurfaceHolder exactly like the example from android developer page: Here

Then I used a FrameLayout to show the camera preview:

// Create an instance of Camera
mCamera = getCameraInstance();

Parameters p = mCamera.getParameters();

// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(;

Everything works good excepting the flash that blinks once and stops.
I tested the app on a Samsung Galaxy S5 with KitKat.

Intent for camera don't fit my needs and Camera2 is excluded.


Answer Source

Found the solution:

 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

    // stop preview before making changes
    try {
    } catch (Exception e){
      // ignore: tried to stop a non-existent preview

    // set preview size and make any resize, rotate or
    // reformatting changes here

    // start preview with new settings
    try {
        //Turn flash on
        Camera.Parameters p = mCamera.getParameters();


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

Add the code to start the flash in the second try-catch of surfaceChanged method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download