Zeek Aran
Zeek Aran

Reputation: 606

Nexus 5 (4.4.2) Flashlight LED not turning on

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: https://i.sstatic.net/HuqF1.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.

Upvotes: 7

Views: 4783

Answers (1)

appmattus
appmattus

Reputation: 2808

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

    try {
        sCamera.setPreviewTexture(new SurfaceTexture(0));
    } catch (IOException ex) {
        // Ignore
    }

Upvotes: 8

Related Questions