4

Currently, I'm using below code to get current screen brightness

...
// for HTC Nexus One and HTC Desire
String cmd = "cat /sys/class/leds/lcd-backlight/brightness";
java.lang.Process p = Runtime.getRuntime().exec(cmd); 
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()),cmd.length());
...

It's ok when I use to get the brightness in HTC devices(Nexus One, Desire). But when run this code on Samsung Galaxy S, this code is invalid because the path in "cmd" is wrong on this device. The problem is I don't have Samsung Galaxy S to find out the correct path of brightness. So could you please tell me the correct path on Samsung Galaxy S device or other ways to do this task! Thanks,

Pham Le Sum
  • 41
  • 1
  • 1
  • 2

3 Answers3

11

The simplest one I could find, to get the screen brightness, using adb:

adb shell settings get system screen_brightness
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
iamtester
  • 119
  • 1
  • 5
9

I know people have given you better ways to do device brightness. Not denying that, but just out of curiosity, if you want to find the relevant files where brightness is stored, here they are:

  • Nexus S: /sys/devices/platform/s3cfb/spi_gpio.3/spi3.0/backlight/s5p_bl/brightness
  • Galaxy Y: /sys/devices/platform/aat1401-backlight.0/backlight/aat1401-backlight/brightness
  • Galaxy S: /sys/devices/platform/omap2_mcspi.1/spi1.0/backlight/omap_bl/actual_brightness

On the Galaxy S, there also seems to be a file named brightness, but actual_brightness seems more accurate. It is capturing the device's screen going half-bright after a certain idle time.

In a nutshell, there does not seem to be a standard path/file on Samsung devices. Of course, this is not the best way to get the brightness, but if you're curious, the above are some of the files.

The best way to figure out is from your desktop, run

adb shell ls -R /sys/devices >files.txt

and then

grep -i  bright files.txt

:-)

tiago
  • 22,602
  • 12
  • 72
  • 88
layman
  • 411
  • 4
  • 9
  • Thanks from 2017 :) For me it was `/sys/devices/mdp.0/qcom,mdss_fb_primary.171/leds/lcd-backlight/brightness` – z3ntu Mar 31 '17 at 14:04
4

Is there a particular reason you're not using the System.Settings class?

Like in:

Can't apply system screen brightness programmatically in Android

Adding screen brightness controls to android application

Community
  • 1
  • 1
Kamen
  • 3,575
  • 23
  • 35
  • System.Settings only return the setting brightness value of the phone. I want to get the brightness value of the screen at a specific time. Example: when the screen on, return value is 176(the same with value in System.Settings). but when the screen is turned off to save battery, the return value is 0. – Pham Le Sum Jun 10 '11 at 10:41