What is the proper way to dim the screen?
I have seen 2 methods so far in my search, both of which I am having trouble with.
Method 1)
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);
Method 2)
IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));
hardware.setScreenBacklight(.5);
Which of these methods is correct? Or is there another that I should be using?
开发者_如何学编程Thanks
I use the code below to do the same
WindowManager.LayoutParams WMLP = getWindow().getAttributes();
WMLP.screenBrightness = 0.15F;
getWindow().setAttributes(WMLP);
The advantage of using the above code is that this affects the screen brightness only in the activity that calls it. So when I move to some other activity (or) quit the application, the phone's default brightness (As set by the user) is restored.
Edit: I forgot to mention that the range of the screenBrightness attribute is 0.0 - 1.0
android.provider.Settings.System.putInt(getContentResolver(), Settings.System.DIM_SCREEN, time); where time is in milli seconds. but this Settings.System.DIM_SCREEN is depricated.
精彩评论