开始
复制一个包含安装步骤和本插件完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-light-sensor`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/light-sensor/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
安装bun add @capgo/capacitor-light-sensorbunx cap sync导入
导入import { LightSensor } from '@capgo/capacitor-light-sensor';API概述
API概述isAvailable
检测是否当前设备上有光线传感器。
在使用传感器之前,应始终检查传感器可用性。检测是否当前设备上有光线传感器。 在使用传感器之前,应始终检查传感器可用性。
import { LightSensor } from '@capgo/capacitor-light-sensor';
const { available } = await LightSensor.isAvailable();start
标题:开始开始监听光线传感器更新。
此操作将在指定间隔开始传感器测量。
使用 addListener 接收传感器数据。
import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.start({ updateInterval: 500 });stop
标题:停止停止监听光线传感器更新。 此操作将停止传感器并节省电池。
import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.stop();checkPermissions
标题:检查权限检查高采样率传感器的当前权限状态。 在 Android 12+ 上,需要 HIGH_SAMPLING_RATE_SENSORS 权限 才能在 200ms 以下的传感器更新间隔下接收传感器数据。
import { LightSensor } from '@capgo/capacitor-light-sensor';
const status = await LightSensor.checkPermissions();requestPermissions
标题:请求权限申请高采样率传感器权限。 在 Android 12+ 上,这将请求 HIGH_SAMPLING_RATE_SENSORS 权限。
import { LightSensor } from '@capgo/capacitor-light-sensor';
const status = await LightSensor.requestPermissions();类型参考
类型参考IsAvailableResult
标题:“IsAvailableResult”传感器是否可用结果。
export interface IsAvailableResult { /** * Whether the light sensor is available on this device. * Always false on iOS as the light sensor API is not available. * * @since 0.0.1 */ available: boolean;}StartOptions
标题:“StartOptions”启动光线传感器监听器的选项。
export interface StartOptions { /** * The desired interval between sensor updates in milliseconds. * On Android 12+, there's a minimum interval of 200ms unless the app * has the HIGH_SAMPLING_RATE_SENSORS permission. * * @default 200 * @since 0.0.1 */ updateInterval?: number;}LightSensorCallback
标题:“LightSensorCallback”光线传感器更新回调函数。
export type LightSensorCallback = (measurement: LightSensorMeasurement) => void;PermissionStatus
标题:权限状态权限请求或检查的结果。
export interface PermissionStatus { /** * Whether the high sampling rate sensor permission is granted. * On Android 12+, this permission is required for update intervals below 200ms. * * @since 0.0.1 */ highSamplingRate: 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';}VersionResult
标题:版本结果插件版本信息。
export interface VersionResult { /** * The current version of the plugin. * * @since 0.0.1 */ version: string;}LightSensorMeasurement
标题:光线传感器测量单个光线传感器测量。
export interface LightSensorMeasurement { /** * Ambient light level in lux (lx). * * @since 0.0.1 */ illuminance: number;
/** * Timestamp of the measurement in seconds since epoch. * * @since 0.0.1 */ timestamp: number;}标题:真实来源
Copy to clipboard本页面由插件生成 src/definitions.ts. 重新同步时,公共 API 上游发生变化。
从 Getting Started 继续
标题为“从 Getting Started 继续”如果您正在使用 Getting Started 来规划仪表板和 API 操作,连接它 使用 @capgo/capacitor-light-sensor 用于在使用 @capgo/capacitor-light-sensor 中的本机功能 API Overview 用于在 API Overview 中的实现细节 介绍 在介绍中实现细节 API 键 在 API 键中实现细节, 设备 在设备中实现细节。