Does anyone know how to adjust the screen brightness programmatically in Mono for Android.
Asked
Active
Viewed 1,109 times
0
-
You'll have to "convert" it from normal Android, but an approach is discussed here: http://stackoverflow.com/questions/6589412/android-screen-brightness-that-doesnt-crash/6591225#6591225 – Jan 18 '13 at 01:32
-
Found a ScreenBrigthness property in c#, but changing has no affect on the brightness of the screen. Cannot find the a "setAttribute" method equivalent in monodroid. Suggestions anyone? – Julien Pierre Jan 18 '13 at 09:10
-
I think you are right. There is no `SetAttribute` method, neither does changing the `Window.Atrribute` properties reflect the changes made. Guess it can be filed as a bug. – Cheesebaron Jan 18 '13 at 11:12
-
I've added a bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=9668 – Cheesebaron Jan 18 '13 at 11:21
-
Does that mean there is no way of changing the screen brightness programmatically? I'm sure there is something. – Julien Pierre Jan 18 '13 at 11:27
-
Well it should be just like on Android, however there seems to be a bug, which prevents this for now. Wait till Xamarin replies on the bug. – Cheesebaron Jan 18 '13 at 11:31
1 Answers
1
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.

Paul Karam
- 4,052
- 8
- 30
- 53