コンテンツにジャンプ

はじめから始める

GitHub

AI-Assisted セットアップを使用してプラグインをインストールできます。AI ツールに Capgo スキルを追加するには、以下のコマンドを使用してください。

ターミナル画面
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.

Manual Setup を好む場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム固有の指示に従ってください:

ターミナルウィンドウ
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 「to」でセンサデータを受信します。

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

光センサの更新を停止する。 この操作は、センサを停止しバッテリーを節約します。

import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.stop();

高サンプリングレートセンサの現在の許可状態を確認します。 Android 12+では、センサ更新間隔が200ms未満の場合、HIGH_SAMPLING_RATE_SENSORS許可が必要です。

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;

PermissionStatus

許可状態

__CAPGO_KEEP_0__

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

LightSensorMeasurement

光センサ測定

光センサの1回の測定

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 の作業を計画する場合、 Using @capgo/capacitor-light-sensor for the native capability in Using @capgo/capacitor-light-sensor, API Overview for the implementation detail in API Overview, 概要 概要の実装詳細については、 API キー API キーの実装詳細については、 デバイス デバイスの実装詳細については。