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.
Restart the phoneIf a particular app or process is conflicting with the flashlight, then a simple reboot should fix it. Just hold the power button and select “Power off” from the menu. Now wait 10-15 seconds and turn it back on. This should fix the problem in most cases.
One of the most common solutions for the problem of flashlight not working is clearing the camera's data and cache. This will reset the system of the camera application. One drawback of this process is that once you delete the data, it will reset the settings of the camera to original settings.
If you have an Android that doesn't offer shortcuts, you'll be able to access the flashlight in the Quick Settings panel when you swipe down from the top of your screen.
This sounds exactly like Syed mentions... try setting a surface view as follows:
try {
sCamera.setPreviewTexture(new SurfaceTexture(0));
} catch (IOException ex) {
// Ignore
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With