我正在使用以下代码设置屏幕亮度,该亮度在大多数手机上都可以正常使用:
protected fun setBrightness(value: Float) {
//Set the system brightness using the brightness variable value
Settings.System.putInt(contentResolver, Settings.System
.SCREEN_BRIGHTNESS, (value * 255).toInt())
//Get the current window attributes
val layoutpars = window.getAttributes()
//Set the brightness of this window
layoutpars.screenBrightness = value
//Apply attribute changes to this window
window.setAttributes(layoutpars)
}
当我传递的值1表示最大值时,它将转换为255,这被认为是设置屏幕亮度的最大值。但是,在小米Mi8上,将值设置为255不会将亮度设置为整个范围,如以下屏幕截图所示:
在打印了一些调试值并进行了试验之后,看起来在小米Mi8上,最大亮度值实际上是1024(或者至少乘以该值将设置整个亮度条)。
似乎不同的android设备可能具有不同的亮度等级。是否有一些API可以获取亮度的最大值,所以我不需要对不同的常数进行硬编码?
最佳答案
它仅适用于某些小米设备。例如,小米Redmi注意事项7的范围为0-4000。
官方文档将SCREEN_BRIGHTNESS范围定义为0-255。因此,我认为没有API能够获得亮度的最大值。
在某些(不是全部)设备上,文件“ / sys / class / leds / lcd-backlight / max_brightness”可以包含最大值。