fix(android): get brightness of the current window on Android, closes #2389 (#2409)

This commit is contained in:
Huang Xin 2025-11-06 02:36:45 +08:00 committed by GitHub
parent b808fc5954
commit 5a3114de48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View file

@ -457,12 +457,19 @@ class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
fun get_screen_brightness(invoke: Invoke) {
val ret = JSObject()
try {
val brightness = Settings.System.getInt(
activity.contentResolver,
Settings.System.SCREEN_BRIGHTNESS
)
val normalizedBrightness = brightness / 255.0
ret.put("brightness", normalizedBrightness)
val window = activity.window
val layoutParams = window.attributes
val brightness = layoutParams.screenBrightness
if (brightness >= 0.0f) {
ret.put("brightness", brightness.toDouble())
} else {
val systemBrightness = Settings.System.getInt(
activity.contentResolver,
Settings.System.SCREEN_BRIGHTNESS
)
ret.put("brightness", systemBrightness / 255.0)
}
} catch (e: Exception) {
ret.put("error", e.message)
ret.put("brightness", -1.0)