__CAPGO_KEEP_0__ 首页
返回插件
@capgo/capacitor-光线传感器
教程
由 github.com/Cap-go

光线传感器

访问环境光线传感器以测量光照度水平(lux)并实时更新

指南

关于光线传感器的教程

使用 @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();

全局参考

继续使用 @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 密钥。