Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing screen brightness efficiently

Tags:

android

I need to change the screen brightness programmatically. I read multiple solutions like this Can't apply system screen brightness programmatically in Android.

My problem is that those solutions implies changing the activity to be effective (having something like a dummy activity finishing immediately) and I would like to avoid the overhead of an activity switch.

Is there any other solution... maybe using native code so that the screen brightness will change immediately ?

like image 321
ben75 Avatar asked Apr 20 '13 11:04

ben75


People also ask

How do I adjust screen brightness quickly?

To change the brightness on an external monitor, use the buttons on it. The Brightness slider appears in action center in Windows 10, version 1903. To find the brightness slider in earlier versions of Windows 10, select Settings > System > Display, and then move the Change brightness slider to adjust the brightness.

Should you keep monitor brightness at 100?

The best monitor brightness for your eyes is between 40 to 60%. However, this value may vary depending on the ambient light conditions. Bright light conditions require higher brightness, while dim light conditions require lower brightness.

Should you keep screen brightness low or high?

If you keep the screen brightness of your gadget at higher than 50 per cent, you still may not risk a permanent damage but many short term problems, such as digital eye strain, eye irritation and dry and fuzzy eyes.

Is there a way to turn down brightness even more?

There are many apps out there designed to turn your Android's screen brightness down even further. A couple of options are the Lower Brightness Screen Filter app and the Screen Filter app. Both of these have the option of lowering your screen brightness from zero to 100%.


1 Answers

The following affects immediately the single activity, no need to restart it. The activity also remembers the screenBrightness attribute over pause/resume.

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 1; // 0f - no backlight ... 1f - full backlight
getWindow().setAttributes(lp);

But it has no effect if you have automatic backlight level enabled in the system settings. This solution should help to turn off automatic backlight.

like image 54
petrch Avatar answered Oct 12 '22 05:10

petrch