This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo LightSensor
一个提供访问设备光线传感器的库。
expo-sensors 中的 LightSensor 提供了对设备光传感器的访问,以便对照度变化做出响应。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
API
import { LightSensor } from 'expo-sensors';
Classes
Type: Class extends DeviceSensor<LightSensorMeasurement>
LightSensor Methods
Subscribe for updates to the light sensor.
EventSubscriptionA subscription that you can call remove() on when you would like to unsubscribe the listener.
Checks user's permissions for accessing sensor.
Promise<PermissionResponse>Returns boolean which signifies if sensor has any listeners registered.
booleanYou should always check the sensor availability before attempting to use it.
Returns whether the light sensor is available and enabled on the device. Requires at least Android 2.3 (API Level 9).
Promise<boolean>A promise that resolves to a boolean denoting the availability of the light sensor.
Asks the user to grant permissions for accessing sensor.
Promise<PermissionResponse>Interfaces
A subscription object that allows to conveniently remove an event listener from the emitter.
Types
Literal type: union
Permission expiration time. Currently, all permissions are granted permanently.
Acceptable values are: 'never' | number