デバイス情報 __CAPGO_KEEP_0__ リポジトリ
このプラグインのインストール手順とフルマークダウンガイドを含むセットアッププロンプトをコピーしてください。
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 syncimport
「import」セクションimport { DeviceInfo } from '@capgo/capacitor-device-info';「1 つのスナップショットを読み取る」セクション
__CAPGO_KEEP_0__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.emitImmediately__CAPGO_KEEP_0__true.- 設定
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のパブリック__CAPGO_KEEP_0__を追跡しています。このページを更新してください。ソースが変更されたときに
続けて始めましょう
「続けて始めましょう」セクションCapacitorを使用している場合 Capacitor デバイス診断用にCapacitorを使用している場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-infoに接続してください。 @capgo/capacitor-device-info Capacitorの概要ページ Using @capgo/capacitor-device-info 圧力値を取得するチュートリアルページ @capgo/capacitor-barometer 焦点圧力値を取得するためのBarometer @capgo/capacitor-light-sensor フォーカスした光センサーの読み取り値用に。