跳过内容

开始

GitHub

您可以使用我们的 AI 助手设置来安装插件。将 Capgo 技能添加到您的 AI 工具中,使用以下命令:

终端窗口
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下提示:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-light-sensor` plugin in my project.

如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:

终端窗口
bun add @capgo/capacitor-light-sensor
bunx cap sync
import { LightSensor } from '@capgo/capacitor-light-sensor';

检查当前设备上的光感应器是否可用。 在使用感应器之前,应始终检查其可用性。

import { LightSensor } from '@capgo/capacitor-light-sensor';
const { available } = await LightSensor.isAvailable();

开始监听光感应器更新。 此操作将在指定间隔开始感应器测量。 使用 addListener 来接收感应器数据。

import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.start({ updateInterval: 500 });

停止监听光感应器更新。 此操作将停止感应器并节省电池。

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();

高采样率传感器请求权限。 在 Android 12+ 中,这个请求 HIGH_SAMPLING_RATE_SENSORS 权限。

import { LightSensor } from '@capgo/capacitor-light-sensor';
const status = await LightSensor.requestPermissions();

表示传感器是否可用结果。

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;
}

启动光线传感器监听器的选项。

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;
}

__CAPGO_KEEP_0__

export type LightSensorCallback = (measurement: LightSensorMeasurement) => void;

权限请求或检查的结果

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';
}

插件版本信息

export interface VersionResult {
/**
* The current version of the plugin.
*
* @since 0.0.1
*/
version: string;
}

光线传感器的单个测量值

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;
}

真实来源

数据源

本页面由插件生成 src/definitions.ts当公共 API 上游发生变化时,请重新运行同步

继续从 Getting Started

继续从 Getting Started

如果您正在使用 Getting Started 来规划仪表板和 API 操作,连接它 使用 @capgo/capacitor-light-sensor 为 Using @capgo/capacitor-light-sensor 中的原生能力 API Overview 为 API Overview 中的实现细节 简介 简介中的实现细节 API 键 API 键中的实现细节 设备 设备中的实现细节