# X系列\_设置屏幕亮度

通过adb指令设置

```bash
# 获取当前亮度模式：返回 1(自动) 或 0(手动)
adb shell settings get system screen_brightness_mode

# 获取当前的亮度数值 (范围 0-255)
adb shell settings get system screen_brightness

# 设置为自动亮度模式 (值为 1)
adb shell settings put system screen_brightness_mode 1

# 设置为手动亮度模式 (值为 0)
adb shell settings put system screen_brightness_mode 0

# 设置屏幕亮度(范围 0-255，数值越大越亮)，慎用，亮度太大可能会导致重启
adb shell settings put system screen_brightness 60
```

通过api设置

```kotlin
//首先需要在AndroidManifest.xml文件中加入权限
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

// 获取当前亮度模式：返回 1(自动) 或 0(手动)
val mode = Settings.System.getInt(
    context.contentResolver,
    Settings.System.SCREEN_BRIGHTNESS_MODE,
    Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL
);

//获取当前的亮度数值 (范围 0-255)
val brightness = Settings.System.getInt(
    context.contentResolver,
    Settings.System.SCREEN_BRIGHTNESS
)

//设置为亮度模式1(自动) 或 0(手动)
Settings.System.putInt(
    context.contentResolver,
    Settings.System.SCREEN_BRIGHTNESS_MODE,
    mode
)

//设置屏幕亮度(范围 0-255，数值越大越亮)，慎用，亮度太大可能会导致重启
var light = lightValue
if (lightValue <= 0) {
    light = 1
}
if (lightValue > 255) {
    light = 255
}
Settings.System.putInt(
    context.contentResolver, 
    Settings.System.SCREEN_BRIGHTNESS, 
    light
)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rayneo.gitbook.io/rayneo-devdoc/chang-jian-wen-ti/faq/x-xi-lie-she-zhi-ping-mu-liang-du.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
