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-android-usagestatsmanager`
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/android-usagestatsmanager/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のAI-Assistedセットアップを使用してプラグインをインストールできます。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-android-usagestatsmanager` plugin in my project.Manualセットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
bun add @capgo/capacitor-android-usagestatsmanagerbunx cap syncimport { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';API の概要
Section titled “API の概要”queryAndAggregateUsageStats
Section titled “queryAndAggregateUsageStats”__CAPGO_KEEP_0__ の使用状況を指定された期間内で検索し、集計します。
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000;const now = Date.now();const stats = await UsageStatsManager.queryAndAggregateUsageStats({ beginTime: oneDayAgo, endTime: now});
for (const [packageName, usageData] of Object.entries(stats)) { console.log(`${packageName}: ${usageData.totalTimeInForeground}ms`);}isUsageStatsPermissionGranted
Section titled “isUsageStatsPermissionGranted”使用状況の許可が与えられているかどうかを確認します。
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await UsageStatsManager.isUsageStatsPermissionGranted();if (!granted) { await UsageStatsManager.openUsageStatsSettings();}openUsageStatsSettings
Section titled “openUsageStatsSettings”使用状況の設定画面を開きます。 使用状況の許可を与える画面を開きます。 許可が与えられている場合でも、設定画面を開きます。
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await UsageStatsManager.openUsageStatsSettings();queryAllPackages
queryAllPackagesのセクションデバイス上のすべてのインストールパッケージを検索します。 QUERY_ALL_PACKAGESの権限が必要です。
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { packages } = await UsageStatsManager.queryAllPackages();packages.forEach(pkg => { console.log(`${pkg.appName} (${pkg.packageName}): v${pkg.versionName}`);});型の参照
型の参照のセクションUsageStatsOptions
UsageStatsOptionsのセクション使用状況統計のクエリのオプションです。
export interface UsageStatsOptions { /** * The inclusive beginning of the range of stats to include in the results. * Defined in terms of "Unix time" */ beginTime: number;
/** * The exclusive end of the range of stats to include in the results. * Defined in terms of "Unix time" */ endTime: number;}UsageStats
UsageStatsのセクションAndroidアプリの使用状況統計です。
export interface UsageStats { /** * The first timestamp of the usage stats. */ firstTimeStamp: number; /** * The last timestamp of the usage stats. */ lastTimeStamp: number; /** * Only available on Android Q (API level 29) and above. * Will be undefined on lower Android versions. */ lastTimeForegroundServiceUsed?: number; /** * The last time the app was used. */ lastTimeUsed: number; /** * Only available on Android Q (API level 29) and above. * Will be undefined on lower Android versions. */ lastTimeVisible?: number; /** * The name of the package. */ packageName: string; /** * Only available on Android Q (API level 29) and above. * Will be undefined on lower Android versions. */ totalForegroundServiceUsed?: number; /** * The total time the app was in the foreground. */ totalTimeInForeground: number; /** * Only available on Android Q (API level 29) and above. * Will be undefined on lower Android versions. */ totalTimeVisible?: number;}UsageStatsPermissionResult
UsageStatsPermissionResultのセクション使用状況統計の許可チェックの結果です。
export interface UsageStatsPermissionResult { /** * Whether the usage stats permission is granted. */ granted: boolean;}PackageInfo
PackageInfoのセクションインストールされているパッケージの基本情報を表します。
export interface PackageInfo { /** Package name */ packageName: string; /** App display name */ appName: string; /** Version name string */ versionName: string; /** Version code number */ versionCode: number; /** First install time in milliseconds since epoch */ firstInstallTime: number; /** Last update time in milliseconds since epoch */ lastUpdateTime: number;}真実の源
真実の源のセクションこのページはプラグインの src/definitions.ts. 公開APIがアップストリームで変更された場合に再度syncを実行してください。
Getting Startedから続けてください
Getting Startedから続けてくださいのセクションCapgoを使用している場合 Getting Started ダッシュボードとAPIの操作を計画するには、APIに接続してください。 Capacitorのネイティブ機能を使用するには、@capgo/capacitor-android-usagestatsmanagerを使用してください。 for the native capability in Using @capgo/capacitor-android-usagestatsmanager, APIの実装詳細については、API Overviewを参照してください。 for the implementation detail in API Overview, 実装詳細については、Introductionを参照してください。 __CAPGO_KEEP_0__のキー API Keysの実装詳細については、API Keysを参照してください。 for the implementation detail in API Keys, and __CAPGO_KEEP_0__の操作を計画するには、__CAPGO_KEEP_0__に接続してください。 __CAPGO_KEEP_0__の実装詳細については、デバイスのページを参照してください。