This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 亮度
提供对 API 的访问以获取和设置屏幕亮度的库。
用于获取和设置屏幕亮度的 API。
🌐 An API to get and set screen brightness.
在安卓系统上,有一个全局系统亮度设置,每个应用都有自己的亮度设置,可选择性地覆盖全局设置。可以使用此 API 设置其中的任意一个值。在 iOS 上,系统亮度设置无法通过编程方式更改;相反,对屏幕亮度的任何更改都会持续有效,直到设备被锁定或关闭电源。
🌐 On Android, there is a global system-wide brightness setting, and each app has its own brightness setting that can optionally override the global setting. It is possible to set either of these values with this API. On iOS, the system brightness setting cannot be changed programmatically; instead, any changes to the screen brightness will persist until the device is locked or powered off.
安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
配置
🌐 Configuration
Are you using this library in an existing React Native app?
如果你没有使用连续本地生成(CNG),或者你是在手动使用本地 android 项目,那么你需要在 AndroidManifest.xml 文件中添加 android.permission.WRITE_SETTINGS 权限:
🌐 If you're not using Continuous Native Generation (CNG) or you're using a native android project manually, then you need to add the android.permission.WRITE_SETTINGS permission to the AndroidManifest.xml file:
用法
🌐 Usage
应用接口
🌐 API
import * as Brightness from 'expo-brightness';
No API data file found, sorry!
错误代码
🌐 Error codes
ERR_BRIGHTNESS
获取或设置应用亮度时发生错误。
🌐 An error occurred when getting or setting the app brightness.
ERR_BRIGHTNESS_MODE
获取或设置系统亮度模式时发生错误。有关详细信息,请参见抛出错误的 nativeError 属性。
🌐 An error occurred when getting or setting the system brightness mode. See the nativeError property of the thrown error for more information.
ERR_BRIGHTNESS_PERMISSIONS_DENIED
尝试设置系统亮度,但未获得用户的适当权限。用户未授予 SYSTEM_BRIGHTNESS 权限。
🌐 An attempt to set the system brightness was made without the proper permissions from the user. The user did not grant SYSTEM_BRIGHTNESS permissions.
ERR_BRIGHTNESS_SYSTEM
获取或设置系统亮度时发生错误。
🌐 An error occurred when getting or setting the system brightness.
ERR_INVALID_ARGUMENT
传递了无效的参数。只允许 BrightnessMode.MANUAL 或 BrightnessMode.AUTOMATIC。
🌐 An invalid argument was passed. Only BrightnessMode.MANUAL or BrightnessMode.AUTOMATIC are allowed.
权限
🌐 Permissions
安卓
🌐 Android
你必须将以下权限添加到你的 app.json 中的 expo.android.permissions 数组里。
🌐 You must add the following permissions to your app.json inside the expo.android.permissions array.
iOS
无需权限。
🌐 No permissions required.