Julien Pierre
Julien Pierre

Reputation: 467

Monodroid - How to adjust device screen brightness programmatically?

Does anyone know how to adjust the screen brightness programmatically in Mono for Android.

Upvotes: 0

Views: 1168

Answers (1)

Paul Karam
Paul Karam

Reputation: 4210

This is a really old post, but since It's not answered and I just came across same problem, what I did was the next:

WindowManagerLayoutParams windowManagerLayoutParams = new WindowManagerLayoutParams();
windowManagerLayoutParams.CopyFrom(Window.Attributes);
windowManagerLayoutParams.ScreenBrightness = 1f; //set screen to full brightness
Window.Attributes = windowManagerLayoutParams;

To set it back to auto:

WindowManagerLayoutParams windowManagerLayoutParams = new WindowManagerLayoutParams();
windowManagerLayoutParams.CopyFrom(Window.Attributes);
windowManagerLayoutParams.ScreenBrightness = -1;
Window.Attributes = windowManagerLayoutParams;

In case you want to save the old brightness and set it back to what it was, you can just store it in a variable and use it again.

Upvotes: 1

Related Questions