スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-device-info`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/device-info/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
互換性
「互換性」セクション@capgo/capacitor-device-info Capacitor 8以降が必要です(@capacitor/core >=8.0.0).
インストール
「インストール」セクションAIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いの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-device-info` plugin in my project.手動でセットアップする場合は、パッケージをインストールしてネイティブプロジェクトをsyncしてください:
npm install @capgo/capacitor-device-infonpx cap syncインポート
「インポート」セクションimport { DeviceInfo } from '@capgo/capacitor-device-info';クイックスタート
「クイックスタート」セクションimport { DeviceInfo } from '@capgo/capacitor-device-info';
const result = await DeviceInfo.getInfo();console.log(result);例: startMonitoring
「例: startMonitoring」というセクションimport { DeviceInfo } from '@capgo/capacitor-device-info';
const result = await DeviceInfo.startMonitoring();console.log(result);例: stopMonitoring
「例: stopMonitoring」というセクションimport { DeviceInfo } from '@capgo/capacitor-device-info';
const result = await DeviceInfo.stopMonitoring();console.log(result);よくある落とし穴
「よくある落とし穴」セクション- リスナー: 画面がアンマウントされたらハンドルを削除します。
- ネイティブ同期: 実行
npx cap syncプラグインのアップグレード後。 - 信頼できる情報源: 信頼
src/definitions.tsGitHub リポジトリ内。
スナップショットを1件読み取る
「スナップショットを1回読み取る」セクションconst snapshot = await DeviceInfo.getInfo();
console.log(snapshot.cpu.cores);console.log(snapshot.memory.usedPercent);console.log(snapshot.storage.freeBytes);console.log(snapshot.sensors?.pressureHpa);cpu.usagePercent はデルタベースです。最初のネイティブサンプルでは省略できます。呼び出し getInfo() を後で再度実行するか、モニタリングを使用して2回目のサンプル以降にCPU使用率が設定された状態を受信してください。
アップデートをストリーミング
「ストリーム更新」セクションconst handle = await DeviceInfo.addListener('deviceInfoUpdate', (sample) => { console.log(sample.sequence, sample.elapsedMs); console.log(sample.cpu.usagePercent); console.log(sample.sensors?.readings);});
const session = await DeviceInfo.startMonitoring({ intervalMs: 1000, emitImmediately: true,});
console.log(session.intervalMs, session.startedAt);動作の監視
「モニタリングの動作」セクションintervalMsデフォルトでは1000ミリ秒。値が250ミリ秒未満の場合は、250.emitImmediatelyデフォルトではtrue.- 設定
durationMsまたはsampleCount自動的にモニタリングを停止するには - 呼び出しを
startMonitoring()モニタリング中に実行すると、新しいオプションでセッションを再起動します。 - すべての
deviceInfoUpdateには1始まりのsequence、セッションのstartedAtタイムスタンプ、およびelapsedMs.
アップデートの停止とリスナーの削除
「アップデートの停止とリスナーの削除」というセクションawait DeviceInfo.stopMonitoring();await handle.remove();
// Or remove every listener registered on this plugin:await DeviceInfo.removeAllListeners();モニタリング状態の確認
「モニタリング状態の確認」セクションconst state = await DeviceInfo.isMonitoring();
if (state.monitoring) { console.log(state.samplesEmitted);}オンボーディング時のセンサーフィールド
「オンボーディング時のセンサーフィールド」セクションconst { sensors, cpu, gpu } = await DeviceInfo.getInfo();
console.log(cpu.temperatureCelsius);console.log(gpu?.temperatureCelsius);console.log(sensors?.batteryTemperatureCelsius);console.log(sensors?.ambientTemperatureCelsius);console.log(sensors?.relativeHumidityPercent);console.log(sensors?.pressureHpa);console.log(sensors?.illuminanceLux);console.log(sensors?.proximityDistanceCm);console.log(sensors?.availableSensors);センサーフィールドは任意です。デバイス、OS、アプリのサンドボックスがそのメトリクスを公開している場合にのみ存在します。
プラットフォーム別の注意点
「プラットフォームの注意点」セクション- iOSでは、公開されているメトリクスの取得に権限は不要です。CoreMotionによるセンサーの利用可能性は報告されますが、CPUやGPUの生の温度は報告されません。
- Androidでは、公開されているメトリクスの取得に権限は不要です。CPUおよびGPUの温度は、ベストエフォートによるサーマルゾーンの読み取り値となります。
- Web サポートはベストエフォートで、ブラウザがネイティブのデバイスセンサーを一貫して公開しないため、オンボードセンサー配列は空で報告されます。
API リファレンス
「API リファレンス」というセクション| メソッド | 戻り値 | 備考 |
|---|---|---|
getInfo() | Promise<DeviceInfoSnapshot> | スナップショットを 1 回読み取ります。 |
startMonitoring(options?) | Promise<StartMonitoringResult> | 定期的なスナップショットを開始するか、新しいオプションでアクティブなセッションを再開します。 |
stopMonitoring() | Promise<StopMonitoringResult> | アクティブなセッションを停止します。 |
isMonitoring() | Promise<MonitoringState> | 現在のセッション状態を返します。 |
addListener('deviceInfoUpdate', listener) | Promise<PluginListenerHandle> | 定期的なスナップショットのリスナーを登録します。 |
removeAllListeners() | Promise<void> | プラグインに登録されているすべてのリスナーを削除します。 |
getPluginVersion() | Promise<PluginVersionResult> | ネイティブプラグインのバージョンを読み取ります。 |
PluginListenerHandle Capacitor によって提供され、以下を備えています remove() その個別のリスナーを削除するため。
スナップショットのタイプ
「スナップショットのタイプ」セクションinterface CpuInfo { cores: number; activeCores?: number; architecture?: string; model?: string; usagePercent?: number | null; maxFrequencyHz?: number; temperatureCelsius?: number;}
interface MemoryInfo { totalBytes?: number; freeBytes?: number; usedBytes?: number; usedPercent?: number; appUsedBytes?: number; appLimitBytes?: number; lowMemory?: boolean; pressure?: 'normal' | 'warning' | 'critical' | 'unknown';}
interface StorageInfo { totalBytes?: number; freeBytes?: number; usedBytes?: number; usedPercent?: number;}
interface GpuInfo { api?: 'metal' | 'opengl' | 'webgl' | 'unknown'; vendor?: string; renderer?: string; version?: string; maxTextureSize?: number; temperatureCelsius?: number;}
type ThermalState = 'nominal' | 'fair' | 'serious' | 'critical' | 'unknown';
interface DeviceInfoSnapshot { timestamp: number; platform: 'ios' | 'android' | 'web'; cpu: CpuInfo; memory: MemoryInfo; storage: StorageInfo; gpu?: GpuInfo; thermalState?: ThermalState; lowPowerMode?: boolean; sensors?: OnboardSensorsInfo;}サイズはバイト単位、 maxFrequencyHz ヘルツ単位、温度は摂氏です。 usagePercent 〜が可能です。 null プラットフォームが計算に必要なサンプル数を取得するまで。
センサーのタイプ
「センサーのタイプ」セクションinterface OnboardSensorDescriptor { type: string; name?: string; vendor?: string; platformType?: number; maximumRange?: number; resolution?: number; powerMilliamp?: number; minDelayMicroseconds?: number; wakeUp?: boolean;}
interface OnboardSensorReading { type: string; unit: string; value: number; name?: string; timestamp?: number;}
interface OnboardSensorsInfo { availableSensors?: OnboardSensorDescriptor[]; readings?: OnboardSensorReading[]; batteryTemperatureCelsius?: number; ambientTemperatureCelsius?: number; relativeHumidityPercent?: number; pressureHpa?: number; illuminanceLux?: number; proximityDistanceCm?: number;}センサー読み取りのタイムスタンプは Unix エポックのミリ秒です。一般的な単位は摂氏、パーセント、hPa、ルクス、センチメートルです。
監視タイプ
セクション「監視タイプ」interface MonitoringOptions { intervalMs?: number; durationMs?: number; sampleCount?: number; emitImmediately?: boolean;}
interface StartMonitoringResult { monitoring: boolean; intervalMs: number; startedAt: number;}
interface StopMonitoringResult { monitoring: boolean;}
interface MonitoringState { monitoring: boolean; intervalMs?: number; startedAt?: number; samplesEmitted?: number;}
interface DeviceInfoUpdate extends DeviceInfoSnapshot { sequence: number; startedAt: number; elapsedMs: number;}
interface PluginVersionResult { version: string;}startedAt, timestampや elapsedMs はミリ秒です。 sequence は以下から始まります 1 各監視セッションについて。
信頼できる情報源
セクション「信頼できる情報源」このリファレンスは、プラグインの公開 API に従っています。 src/definitions.tsそのソースが変更されたら、このページを更新してください。
Getting Startedの続きを進める
「Getting Started からの続き」セクション使用している場合 スタートガイド デバイス診断には、これを以下と接続してください: @capgo/capacitor-device-info 概要については、 @capgo/capacitor-device-info の使い方 チュートリアルページについては、 @capgo/capacitor-barometer 特定の圧力測定値については、 @capgo/capacitor-light-sensor 光センサーを集中的に読み取るために。