Android 11 获取系统亮度
时间: 2024-05-08 16:22:08 浏览: 90
在 Android 11 中,获取系统亮度可以通过以下方式:
1. 获取当前屏幕亮度:
```
int currentBrightness = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
```
2. 获取当前屏幕亮度模式:
```
int currentBrightnessMode = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE);
```
其中,`currentBrightnessMode` 的值为:
- `Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL`:手动模式。
- `Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC`:自动模式。
3. 获取当前自动亮度调节的亮度范围:
```
ContentResolver cr = getContentResolver();
Uri uri = Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS);
int minBrightness = Settings.System.getInt(cr, "screen_brightness_min");
int maxBrightness = Settings.System.getInt(cr, "screen_brightness_max");
```
其中,`minBrightness` 和 `maxBrightness` 分别表示当前设备支持的亮度范围的最小值和最大值。
阅读全文