始め方
このプラグインのインストール手順とフルマークダウンガイドを含む設定コマンドをコピーしてください。
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.
Install
Section titled “Install”You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-device-info` plugin in my project.If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
bun add @capgo/capacitor-device-infobunx cap syncImport
Section titled “Import”import { DeviceInfo } from '@capgo/capacitor-device-info';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 最初のネイティブサンプルでは省略できます。2回目のサンプル後にCPU使用率が充填された場合に再度呼び出すか、監視を使用して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);});
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サポートはベストエフォートであり、ブラウザがnativeデバイスセンサを一貫して公開していないため、オンボードセンサ配列を空に報告します。
Type Reference
「Type Reference」のセクションDeviceInfoSnapshot
「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
「OnboardSensorsInfo」のセクションexport interface OnboardSensorsInfo { availableSensors?: OnboardSensorDescriptor[]; readings?: OnboardSensorReading[]; batteryTemperatureCelsius?: number; ambientTemperatureCelsius?: number; relativeHumidityPercent?: number; pressureHpa?: number; illuminanceLux?: number; proximityDistanceCm?: number;}MonitoringOptions
「MonitoringOptions」のセクションexport interface MonitoringOptions { intervalMs?: number; durationMs?: number; sampleCount?: number; emitImmediately?: boolean;}このページはプラグインから生成されています。 src/definitions.tspublic API の変更をアップストリームで再実行してください。
Getting Started から続けてください
Getting Started から続けてくださいCapgo を使用している場合 Capgo を使用している場合、デバイス診断用に接続してください。 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-info @capgo/capacitor-device-info を使用して概要を確認してください。 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-barometer @capgo/capacitor-barometer を使用してチュートリアルを実行してください。 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-barometer @capgo/capacitor-barometer for focused pressure readings, and @capgo/capacitor-light-sensor for focused light sensor readings。