はじめから始める
このプラグインのインストール手順と全マークダウンガイドを含むセットアップ用の質問をコピーします。
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.
インストール
インストールbun add @capgo/capacitor-device-infobunx cap syncインポート
インポートimport { DeviceInfo } from '@capgo/capacitor-device-info';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使用率が充填された後の2回目のサンプルを使用します。
ストリームの更新
セクション「ストリームの更新」const handle = await DeviceInfo.addListener('deviceInfoUpdate', (sample) => { console.log(sample.sequence, sample.elapsedMs); console.log(sample.cpu.usagePercent); console.log(sample.sensors?.readings);});
await DeviceInfo.startMonitoring({ intervalMs: 1000, emitImmediately: true,});更新を停止
セクション「更新を停止」await DeviceInfo.stopMonitoring();await handle.remove();自動停止も可能です:
await DeviceInfo.startMonitoring({ intervalMs: 1000, durationMs: 60_000, sampleCount: 60,});監視状態を確認
セクション「監視状態を確認」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 サポートはベストエフォートであり、ブラウザがネイティブ デバイス センサーを一貫して公開していないため、空のオンボード センサー配列を報告します。
型参照
型参照 セクションDeviceInfoSnapshot
デバイス情報スナップショットexport interface DeviceInfoSnapshot { timestamp: number; platform: 'ios' | 'android' | 'web'; cpu: CpuInfo; memory: MemoryInfo; storage: StorageInfo; gpu?: GpuInfo; thermalState?: ThermalState; lowPowerMode?: boolean; sensors?: OnboardSensorsInfo;}OnboardSensorsInfo
センサーのオンボード情報export interface OnboardSensorsInfo { availableSensors?: OnboardSensorDescriptor[]; readings?: OnboardSensorReading[]; batteryTemperatureCelsius?: number; ambientTemperatureCelsius?: number; relativeHumidityPercent?: number; pressureHpa?: number; illuminanceLux?: number; proximityDistanceCm?: number;}MonitoringOptions
監視オプションexport interface MonitoringOptions { intervalMs?: number; durationMs?: number; sampleCount?: number; emitImmediately?: boolean;}真実の源
真実の源このページはプラグインから生成されています。 src/definitions.ts API のアップストリームのパブリック変更が発生した場合に再度同期を実行してください。
Getting Started から続けて
Getting Started から続けてあなたが Getting Started デバイスの診断に使用する場合、 @capgo/capacitor-device-info の概要については @capgo/capacitor-device-info のチュートリアルについては @capgo/capacitor-barometer の圧力値を取得するには @capgo/capacitor-light-sensor の光センサーの値を取得するには