コンテンツにジャンプ

Getting Started

GitHub

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-android-usagestatsmanager` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

Terminal window
bun add @capgo/capacitor-android-usagestatsmanager
bunx cap sync
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';

queryAndAggregateUsageStats

Section titled “”

Queries and aggregates usage stats for the given time range.

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

isUsageStatsPermissionGranted

使用状況統計の許可が付与されているかどうかを確認します。

import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await UsageStatsManager.isUsageStatsPermissionGranted();
if (!granted) {
await UsageStatsManager.openUsageStatsSettings();
}

openUsageStatsSettings

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}`);
});

Type Reference

Type Reference

UsageStatsOptions

UsageStatsOptions

__CAPGO_KEEP_0__の使用統計情報の取得オプションです。

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;
}

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;
}

使用統計の許可チェックの結果です。

export interface UsageStatsPermissionResult {
/**
* Whether the usage stats permission is granted.
*/
granted: boolean;
}

インストール済みのパッケージの基本情報を表します。

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. upstream の API が変更されたときに、再度 Sync を実行してください。

Getting Started から続けてください

Getting Started から続けてください

あなたが「 Getting Started 」を使用してダッシュボードと API の操作を計画している場合、 「@capgo/capacitor-android-usagestatsmanager」 for the native capability in Using @capgo/capacitor-android-usagestatsmanager, 「@API/__CAPGO_KEEP_1__-android-usagestatsmanager」 のネイティブ機能の実装詳細は「API Overview」 概要 概要の実装詳細については API キー API キーの実装詳細については デバイス デバイスの実装詳細については