37

Is there a way to set the LED intensity that I desire? I know that to turn on the LED I use:

     p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
     mycam.setParameters(p);

But this code just turns on the LED. But is there a way to set different intensities to the LED for a stronger light or to reduce the light intensity?

VC.One
  • 12,230
  • 4
  • 21
  • 51
Buda Gavril
  • 19,769
  • 35
  • 114
  • 174
  • I don't think so, but I am not sure. And if so it definitely won't work on all devices. You might also consider removing the [flash] tag since it is for Adobe flash and someone might get here expecting the question to be related to that. – FoamyGuy May 11 '11 at 20:31
  • 2
    My HTC Evo comes with a "flashlight" feature that uses the LED "flash", and has three different brightness settings. Works like a champ too. So there must be **some** way to do it. Since its a built-in app, I suppose it could be device-specific though. – T.E.D. May 11 '11 at 20:42
  • hopefully my answer would help you. – N-JOY Aug 03 '11 at 05:16

5 Answers5

26

HTC has an alternative API that supports this, however it's only on HTC Sense devices, and as of Gingerbread they've changed the permissions so it's only for their Flashlight app, not third party ones (unless you use root).

But on 2.2 HTC devices you can use it by writing a string to /sys/devices/platform/flashlight.0/leds/flashlight/brightness. This controls if the LED is on and how bright it is. For maximum brightness write "128\n", half brightness write "64\n". Easy to test from adb shell:

echo "128" > /sys/devices/platform/flashlight.0/leds/flashlight/brightness

And finally turn it off by writing "0\n" there.

Kevin TeslaCoil
  • 9,806
  • 1
  • 37
  • 33
  • Thanks @Kevin TeslaCoil.. I got what you told. But dont know how to implement it. Can you show a guide or tutorial related to this ? – Kartik Domadiya Aug 09 '11 at 04:06
  • So far i got http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bequick/flashlight/HtcLedFlashlight.java?r=209 ..... – Kartik Domadiya Aug 09 '11 at 07:36
  • Quick Settings, cool. I think you're just missing the \n part. Here's what I'm using for TeslaLED http://teslacoilsw.com/tmp/SysDevicesLED.java – Kevin TeslaCoil Aug 10 '11 at 04:05
  • need your help again. The way you gave here for changing the intensity of flash light doesnt work on GingerBread. And again one more weired problem is there. I have two modes viz light and bright.. when i select light and then bright e.thing works fine. But when i select bright first and then light, intensity of light is not getting changed... – Kartik Domadiya Oct 04 '11 at 09:59
  • 3
    is there an overview shomewhere of things that can be changed by writing to the sysfs? – Pierre Barbera Mar 21 '13 at 12:52
  • Thanks for your answer. But I use TinyFlashLight (https://play.google.com/store/apps/details?id=com.devuni.flashlight) in my HTC phone, it can adjust brightness flashlight without root. So could you tell me how to do it? – VAdaihiep Jul 16 '13 at 03:06
  • 3
    This post was written 3 years ago. is there some update? – nkint Mar 31 '14 at 21:46
5

Short answer is: NO.
Longer answer - maybe on some devices using undocumenterd calls / parameters. Supported flash modes, and their meanings (and behaviours) differ from device to device.

Your best option is to query supported flash modes, and hope they work as intented.

Sergey Glotov
  • 19,479
  • 11
  • 78
  • 93
Konstantin Pribluda
  • 12,042
  • 1
  • 26
  • 34
4

Try to set different Flash Modes available for Camera parameters.

* FLASH_MODE_OFF
* FLASH_MODE_AUTO
* FLASH_MODE_ON
* FLASH_MODE_RED_EYE
* FLASH_MODE_TORCH

you can set Flash mode using setFlashMode() method.

This was just for camera back light. but if you want to change complete screen intensity. have a look at the example here.

N-JOY
  • 10,164
  • 7
  • 47
  • 69
2

I have tried this in my Samsung Galaxy S3 Mini. I have not tried on other devices.

Whenever i do this (while the led is ON):

public void changeIntensity()
{
    cam.stopPreview();
    cam.startPreview();
}

The LED rotates between 3 levels of intensity. It makes no sense, but it works.

MXS
  • 121
  • 6
2

Try to find the code of this function:

private native final void native_setParameters(String params);

I beleive that you will find out if this is possible when you look through it.

Looking at the publics, it seems impossible

Sherif elKhatib
  • 44,650
  • 15
  • 84
  • 105