jfversluis / Plugin.Maui.ScreenBrightness

Plugin.Maui.ScreenBrightness provides the ability to get or set the screen brightness inside a .NET MAUI application.
MIT License
45 stars 3 forks source link

Android sets / returns values in a different scale #1

Closed nll closed 1 year ago

nll commented 1 year ago

From the Android documentation:

Also from my testing the system setting does not reflect the value set on the window layout params, so I suspect the code should be something like this:

var context = Platform.CurrentActivity;
if (context == null) {
    return 0;
}

var windowBrightness = window.Attributes.ScreenBrightness;
if (windowBrightness < 0) {
    return Settings.System.GetInt(context.ContentResolver, Settings.System.ScreenBrightness) / 255;
}

return windowBrightness;
jfversluis commented 1 year ago

Oh good catch! If you want, feel free to open a PR!

jfversluis commented 1 year ago

Fixed by #2