6

Entire question is in the title, so I would like to emphasis as I can that:

  • I am interested in current value (not in current settings of it)

  • I am interested in real value (so if the brightness of the screen is now lower than a second before, the value should be lower as well)

Sadly, despite reading numerous posts, I don't know the answer. I wrote little utility, that every one second shows time and brightness. And it does not work -- because when the phone (LG L5 with Android 4.0) automatically lowers the brightness (the screen is dimmed, and there is no doubt about it) the values stay the same!

Here is the relevant piece of code:

try
{
  float sys_brightness = android.provider.Settings.System
                         .getFloat(getContentResolver(),
                                   android.provider.Settings
                                   .System.SCREEN_BRIGHTNESS);

  WindowManager.LayoutParams lp = getWindow().getAttributes();  
  float dim = lp.dimAmount;
  float scr_brightness = lp.screenBrightness;
  boolean dim_changed = (lp.flags & WindowManager.LayoutParams
                                    .DIM_AMOUNT_CHANGED)>0;  

  textView.setText(String.format("%02d:%02d:%02d", hours, minutes, seconds)+" "
                   +String.format("%02f, %02f, %02f", sys_brightness,dim,scr_brightness)
                   +" "+Boolean.toString(dim_changed));
}
catch (SettingNotFoundException ex)
{
  textView.setText("excepton");
}

For the record, values are -- 92, 1.0, -1.0, false. All the time.

QUESTION -- how to read current, real brightness/dim value?

I added clock to output to be sure, my readings are ticking. And they are.

Ry-
  • 218,210
  • 55
  • 464
  • 476
greenoldman
  • 16,895
  • 26
  • 119
  • 185
  • 1
    I think that you confuse brightness with backlight. "automatically lowers the brightness" -> this is power management adjusting the backlight to save energy. It has nothing (AFAIK) to do with brightness. – wojciii Aug 02 '12 at 15:27
  • @wojci, I think you confuse technical aspect how the phone screen is lit (not every screen has to back lited) with the way the settings are set in given phone. But on the other hand, if Android is confused the same way... I will check it. – greenoldman Aug 02 '12 at 15:56
  • I have the same problem, I am trying to change behavior when I am at dim or full brightness while using a wake lock screen dim, any ideas would be a big help – draksia Jan 22 '13 at 16:37
  • Did you ever figure this out? I'm interested in reading screen brightness – Kmanc Feb 20 '14 at 21:35
  • @Kmanc, honestly I don't remember, but I doubt it. System level programming on Android is so painful, that after 2 utilities I gave up, it is not worth my time. – greenoldman Feb 20 '14 at 22:39
  • Ok, well thank you anyway. I think I may have figured out part of the problem, though this post is old, so it may not be of any use to you. Basically, if auto-brightness is enabled, the reading from "android.provider.settings....." will always report whatever number the brightness level is manually set to, regardless of the actual brightness. So I set up a case statement that returns "auto enabled", or the brightness level if auto is disabled – Kmanc Feb 20 '14 at 22:44

2 Answers2

1

If you do grep -r "SCREEN_BRIGHTNESS" * in android/system/frameworks (android source code) you will find: BrightnessController.java which is used to control brightness. Maybe you can use this class as inspiration.

wojciii
  • 4,253
  • 1
  • 30
  • 39
  • Thank you very much. I am out of luck though, I checked what `IPowerManager` has, and there is `setBacklightBrightness` metod, but there is no counterpart for it to read this value back :-(. Now, I started to browse Android sources, maybe something will surface. – greenoldman Aug 03 '12 at 21:06
  • 1
    It is an AIDL interface - which can be used for RPC. This looks like your issue: https://groups.google.com/forum/?fromgroups#!topic/android-developers/Ozted8DSZ60. – wojciii Aug 03 '12 at 23:44
  • I already found that there is no `getBacklightBrightness` anywhere, so it is a dead end. However there is interesting method `isScreenBright` in `PowerManagerService`, and now I am struggling to get an instance of it. – greenoldman Aug 04 '12 at 19:57
0

The following snippet produces a floating point number varying from 0 to 1 which seems to correspond t the brightness.

WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
Float darkness = layoutParams.screenBrightness;

It seems that the Asus tablet shows a dim screen when brightness is set to zero. The kindle Fire is quite dark and retreats behind the lock screen.

user462990
  • 5,472
  • 3
  • 33
  • 35
  • Your code is **exactly** what I posted in question -- it does not work properly. It returns theoretical value -- i.e. the brightness which is supposed to be set -- not, the value which is actually set (for physical screen). – greenoldman Aug 10 '12 at 15:51