跳过内容

光线传感器__CAPGO_KEEP_0__仓库

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

终端窗口
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();

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

复制到剪贴板

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

requestPermissions

复制到剪贴板

复制到剪贴板

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

类型参考

类型参考部分

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

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

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

复制到剪贴板

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 为在使用 @capgo/capacitor-light-sensor 中的原生功能 API Overview 为 API Overview 的实现细节 __CAPGO_KEEP_0__ 为 Introduction 的实现细节 API 键 为 API 键的实现细节提供键,和 设备 为设备的实现细节提供键。