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.

4

2 に答える 2

1

grep -r "SCREEN_BRIGHTNESS" *(アンドロイドソースコード)で行うandroid/system/frameworksと、明るさを制御するために使用されるBrightnessController.javaが見つかります。このクラスをインスピレーションとして使用できるかもしれません。

于 2012-08-03T11:49:15.467 に答える
0

次のスニペットは、明るさに対応しているように見える 0 から 1 まで変化する浮動小数点数を生成します。

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

明るさをゼロに設定すると、Asus タブレットの画面が暗くなるようです。kindle Fire はかなり暗く、ロック画面の後ろに隠れます。

于 2012-08-10T15:16:19.400 に答える