Q:

Setting Parameters.FLASH_MODE_TORCH doesn't work on Droid X 2.3

I am writing an app that sets the flash mode to torch.  I have been testing the application on my Droid X, and the LED light does not come on.  I tried it on a Droid Incredible and it worked fine.  I can't figure out what the problem is.  Here is part of my code for turning on torch mode.
    Camera mCamera = Camera.open();
    Camera.Parameters params = mCamera.getParameters();
    if(params.getFlashMode() != null){
        params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    }
    mCamera.setParameters(params);

I have added mCamera.startPreview(); because I read that should make a difference, but it doesn't.  I also made a list of available flash modes and displayed them to the screen to make sure that my Droid X does have torch mode, and it was in the list.  I even created a new application from code I found online that turns the LED flash on and off with a button.  Again it worked fine on the Droid Incredible but not the Droid X.  Is there something I am missing to get this to run on the Droid X, or could it be something with Gingerbread?  The Droid X is running Gingerbread and the Droid Incredible is running FroYo.

A:

There are quite a few quirks when setting FLASH_MODE_TORCH.
Often you need to start a camera preview:
Camera mCamera = Camera.open();
mCamera.startPreview();
Camera.Parameters params = mCamera.getParameters();
if(params.getFlashMode() != null){
    params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(params);

That may resolve it on some phones, other phones also require the preview to be drawn to a SurfaceView. This can be done by implementing SurfaceHolder.Callback interface in your activity.
See an example here.

A:

It could be that the Droid X doesn't support Torch Mode.  Try something like this:
        List<String> pList = camera.getParameters().getSupportedFlashModes();

        if (pList.contains(Parameters.FLASH_MODE_TORCH))
            parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);

         camera.setParameters(parameters);

