Skip to content Skip to sidebar Skip to footer

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);

Solution 1:

I use the code below to do the same

WindowManager.LayoutParamsWMLP= 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

Solution 2:

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.

Post a Comment for "What Is The Proper Way To Dim The Screen?"