コンテンツにジャンプ

はじめから始める

GitHub

Capgoの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 Start listening to light sensor updates. This will begin sensor measurements at the specified interval. Use

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

Section titled “stop”

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

checkPermissions

Copy to clipboard

Section titled “checkPermissions”

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

requestPermissions

Copy to clipboard

Section titled “requestPermissions”

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

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. upstream の API が変更されたときに、再度 sync を実行してください。

Getting Started から続けてください。

Getting Started というセクション

Capgo を使用している場合 Getting Started ダッシュボードと API の作業を計画するには、Capgo を接続してください。 Capgo の @capgo/capacitor-light-sensor を使用 Capgo の @capgo/capacitor-light-sensor のネイティブ機能 Capgo の API の概要 Capgo の API の実装詳細 Capgo の __CAPGO_KEEP_0__ の概要 Capgo の実装詳細 API キー API キーに関する実装詳細、そして デバイス デバイスに関する実装詳細