Can I change the LED intensity of an Android device?
Asked Answered
C

6

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?

Congruous answered 11/5, 2011 at 20:26 Comment(3)
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.Pinchhit
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.Noe
hopefully my answer would help you.Denticulate
M
27

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.

Mercedezmerceer answered 5/8, 2011 at 16:32 Comment(7)
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 ?Curvilinear
So far i got code.google.com/p/quick-settings/source/browse/trunk/… .....Curvilinear
Quick Settings, cool. I think you're just missing the \n part. Here's what I'm using for TeslaLED teslacoilsw.com/tmp/SysDevicesLED.javaMercedezmerceer
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...Curvilinear
is there an overview shomewhere of things that can be changed by writing to the sysfs?Reno
Thanks for your answer. But I use TinyFlashLight (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?Marcy
This post was written 3 years ago. is there some update?Pattypatulous
C
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.

Code answered 5/8, 2011 at 11:2 Comment(0)
D
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.

Denticulate answered 2/8, 2011 at 7:11 Comment(0)
P
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

Pozzuoli answered 5/8, 2011 at 9:3 Comment(0)
E
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.

Erna answered 6/12, 2013 at 10:31 Comment(0)
M
0

This feature is officially available on Android devices that are running Android 13 or higher.

Android Doc

Sample Code

Mindoro answered 7/10, 2023 at 16:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.