7

I wrote a simple flashlight app that I've tested on an HTC Sensation, Nexus 7, HTC One, Moto X, Galaxy S3, Galaxy S4, and a Nexus 5. The only one that it doesn't work on is the Nexus 5. It doesn't throw an exception so finding out what's wrong is proving difficult.

Here's the code I've been using that works on everything but:

            sCamera = Camera.open();
            sParameters = sCamera.getParameters();
            sParameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
            sCamera.setParameters(sParameters);
            sCamera.startPreview();

And here's a screenshot of what happens in LogCat when it should be turning the LED on: http://i.imgur.com/vXn5PoH.png

I've pulled the list of flash modes from the Nexus 5 and it says they are: on, off, auto, torch, and red-eye. These are as expected. I've tested with flipping between on, off, and torch, but nothing even makes the light flicker. And I know the LED isn't broken because other flashlight apps work fine.

Zeek Aran
  • 485
  • 3
  • 16
  • did you use surface view with the camera object, as some devices need surface view to make the camera object and flash work [link](http://stackoverflow.com/questions/21276908/turn-on-off-flash light-) using-surfaceview, maybe this might not be the problem as i haven't seen the code – Syed Raza Mehdi Mar 11 '14 at 07:45

1 Answers1

8

This sounds exactly like Syed mentions... try setting a surface view as follows:

    try {
        sCamera.setPreviewTexture(new SurfaceTexture(0));
    } catch (IOException ex) {
        // Ignore
    }
appmattus
  • 2,620
  • 21
  • 15