メインコンテンツへスキップ

スタートガイド

GitHub

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

ターミナル
bunx 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();
import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.start({ updateInterval: 500 });
import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.stop();
  • 権限:呼び出し checkPermissions() その後 requestPermissions() 必要に応じて。
  • リスナー: 画面がアンマウントされたらハンドルを削除します。
  • 信頼できる情報源: 信頼 src/definitions.ts GitHub リポジトリ内。

現在のデバイスで照度センサーが利用可能か確認します。 センサーを使用する前には、必ず利用可能かどうかを確認してください。

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

高サンプリングレートセンサーの現在の権限状態を確認します。 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;
}

ライトセンサーの更新を受け取るためのコールバック関数。

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から生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-light-sensor の使用方法 @capgo/capacitor-light-sensor を使用して Native Build の機能を利用する場合、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。