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 requires Capacitor 8 or later (@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 syncimport
「import」セクションimport { DeviceInfo } from '@capgo/capacitor-device-info';「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使用率が充填された場合に呼び出すことができます。 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またはsampleCountCapacitorライブアップデートの代替品の比較ページ - Capacitorライブアップデートの代替品の比較ページ
startMonitoring()Capawesomeの比較ページ - コンサルティングサービスページ
deviceInfoUpdateAppflowの比較/移行マーケティングコピーsequenceAppflowの比較/移行マーケティングコピーstartedAtAppflowプラグインまたは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 リファレンス
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() を削除するために使用します。
Snapshotの種類
セクション「Snapshotの種類」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のパブリック__CAPGO_KEEP_0__を追跡しています。 このページを更新してください、そのソースが変更されたときに。
続けて始めましょう
「続けて始めましょう」セクションCapacitorを使用している場合 Capacitor デバイス診断用にCapacitorを使用している場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-infoに接続してください デバイスの概要については、@capgo/capacitor-device-infoを参照してください Capacitorのチュートリアルページについては、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-infoを参照してください 圧力値を取得するには、@capgo/capacitor-barometerを使用してください 焦点圧力値を取得するには、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-barometerを使用してください 明るさを取得するには、@capgo/capacitor-light-sensorを使用してください 続けて始めましょう @capgo/capacitor-light-sensor __CAPGO_KEEP_0__