我用下面的设置系统自动亮度模式和水平:
I'm using the following to set the system auto brightness mode and level:
android.provider.Settings.System.putInt(y.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
android.provider.Settings.System.putInt(y.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, y.brightness1);
我可以改变或关闭自动brighess,并设置不同的等级。设置似乎正确应用 - 我可以去到设置 - >显示 - >亮度和whanever设置我设置实际上是正确显示。但是,实际的屏幕并没有改变它的亮度。如果我只需轻按在显示设置滑块,然后一切都被应用。
I can change auto-brighess on and off, and set different levels. The settings seem to be applied properly -- I can go to into Settings --> Display --> Brightness, and whanever setting I set is actually shown correctly. However, the actual screen isn't changing its brightness. If i just tap on the slider in Display Settings, then everything gets applied.
我shoudl提到,我正在withat主要活动的应用程序,而且这些设置是在的BroadcastReceiver得到应用。我曾尝试创建一个虚拟活动和测试的东西有,但得到了同样的结果。
I shoudl mention that I'm running an app withat a main activity, and these settings are getting applied in the BroadcastReceiver. I did try to create a dummy activity and tested the stuff there, but got the same results.
OK,找到了答案在这里: 刷新从插件的显示?
OK, found the answer here: Refreshing the display from a widget?
基本上,不得不做出这样的处理亮度变化的透明活动。什么是不是在帖子中提到的是,你必须做的:
Basically, have to make a transparent activity that processes the brightness change. What's not mentioned in the post is that you have to do:
Settings.System.putInt(y.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
Settings.System.putInt(y.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, brightnessLevel);
然后执行
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
如果你调用finish()应用更改之后,亮度会从来没有真正改变,因为布局必须创建亮度设置应用之前。所以,我结束了创建一个线程,有一个300毫秒的延迟,然后叫完成()。
And if you call finish() right after applying the changes, brightness will never actually change because the layout has to be created before the brightness settings is applied. So I ended up creating a thread that had a 300ms delay, then called finish().