Setting .FLASH_MODE_TORCH parameters does not work on Droid X 2.3

I am writing an application that sets the flash mode to a torch. I tested the application on my Droid X and the LED does not light up. I tried this on Droid Incredible and it worked great. I can’t understand what the problem is. Here is part of my code to enable 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 added mCamera.startPreview (); because I read that it should matter, but it is not. I also made a list of available flash modes and displayed them on the screen to make sure my Droid X had a torch mode and it was on the list. I even created a new application from code that I found on the Internet that turns on and off the LED flash with a button. Again, it worked great on Droid Incredible, but not on Droid X. Is there something I’m missing to get it to work on Droid X, or could it be something with Gingerbread? Droid X runs Gingerbread, while Droid Incredible launches FroYo.

+4
source share
4 answers

There are quite a few quirks in setting FLASH_MODE_TORCH.

Often you need to run 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); 

This may allow it on some phones; other phones also require previews for SurfaceView. This can be done by implementing the SurfaceHolder.Callback interface in your activity. An example is here .

+6
source

Perhaps Droid X does not 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); 
+4
source

Refer to Issue 191453 :

 SurfaceTexture mDummy = new SurfaceTexture(1); // any int argument will do camera.setPreviewTexture(mDummy); camera.startPreview(); 
+1
source

The only thing I found that works on Droid X is the code provided by Siddhpura Amit, partly on the page in this answer Use flashlight for camera in Android . It checks the manufacturer and checks to see if it contains the string "motorola". If so, he has a special code that can turn the camera flash LED on or off. I can verify that it works, since I have a Motorola Droid X.

0
source

All Articles