Getting Started
インストールステップとこのプラグインのフルマークダウンガイドを含むセットアッププロンプトをコピーしてください。
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).
インストール
「インストール」というタイトルのセクションCapgoの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.手動セットアップの場合、パッケージをインストールし、ネイティブプロジェクトを同期してください:
npm install @capgo/capacitor-device-infonpx cap syncインポート
「インポート」のセクションimport { DeviceInfo } from '@capgo/capacitor-device-info';「1つのスナップショットを読み取る」のセクション
contextconst 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 deltaベースです。最初のネイティブサンプルでは省略できます; 2番目のサンプル後には、CPU使用率が充填された監視を使用して呼び出してください。 getInfo() ストリームの更新
「ストリームの更新」セクション
クリップボードにコピー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.emitImmediatelyStream updatestrue.- 設定
durationMsまたはsampleCount監視を自動で停止します。 - 呼び出し
startMonitoring()監視が有効な場合は、セッションを再起動して新しいオプションを使用します。 - すべて
deviceInfoUpdate1を含む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センサーの利用可能性を報告しますが、RAW CPUまたはGPU温度は報告しません。
- Androidでは、公開メトリックに許可が必要ありません。CPUおよびGPU温度はベストエフォートの熱帯域読み取りです。
- Webサポートはベストエフォートであり、ブラウザがネイティブデバイスセンサを一貫して公開していないため、空のオンボードセンサーアレイを報告します。
API reference
「API reference」セクション| メソッド | 戻り値 | 注意 |
|---|---|---|
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 真実の源
This reference follows the public API in the plugin’s src/definitions.ts真実の源
続けてはじめから
「続けてはじめから」Capacitorを使用している場合 はじめから デバイス診断に使用する場合、 @capgo/capacitor-device-info の概要については Using @capgo/capacitor-device-info のチュートリアルページについては @capgo/capacitor-barometer 圧力値を取得するには @capgo/capacitor-light-sensor フォーカスした光センサーの読み取り値用に。