指南
关于光线传感器的教程
使用 @capgo/capacitor-light-sensor
Capacitor 插件,用于访问设备的环境光线传感器。
安装
bun add @capgo/capacitor-light-sensor
bunx cap sync
此插件暴露了什么
isAvailable- 检查当前设备上的光线传感器是否可用。您始终应在尝试使用传感器之前检查传感器可用性。start- 开始监听光线传感器更新。该操作将在指定间隔开始传感器测量。使用addListener接收传感器数据。stop- 停止监听光线传感器更新。该操作将停止传感器并节省电池。checkPermissions- 检查当前高采样率传感器的权限状态。Android 12+ 上,高采样率传感器更新间隔低于 200ms 需要 HIGH_SAMPLING_RATE_SENSORS 权限。
示例用法
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+ 上,高采样率传感器更新间隔低于 200ms 需要 HIGH_SAMPLING_RATE_SENSORS 权限。
import { LightSensor } from '@capgo/capacitor-light-sensor';
const status = await LightSensor.checkPermissions();
全局参考
- GitHub: https://github.com/Cap-go/capacitor-light-sensor/
- 文档: /docs/plugins/light-sensor/
继续使用 @capgo/capacitor-light-sensor
如果您正在使用 使用 @capgo/capacitor-light-sensor 来规划仪表板和API操作,连接它到 @capgo/capacitor-light-sensor 查看 @capgo/capacitor-light-sensor 的实现细节 开始 查看开始的实现细节 API概述 for the implementation detail in API 介绍 简介 for the implementation detail in 简介, 和 API 密钥 for the implementation detail in API 密钥。