__CAPGO_KEEP_0__

はじめに

GitHub

AI-Assisted セットアップを使用してプラグインをインストールできます。次のコマンドを使用して、Capgo スキルをAIツールに追加してください。

コピー
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.

インストール

ターミナルウィンドウ
bun add @capgo/capacitor-android-usagestatsmanager
bunx cap sync

インポート

インポート
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';

APIの概要

APIの概要

queryAndAggregateUsageStats

queryAndAggregateUsageStatsの概要

queryAndAggregateUsageStatsの概要

import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000;
const now = Date.now();
const stats = await CapacitorUsageStatsManager.queryAndAggregateUsageStats({
beginTime: oneDayAgo,
endTime: now
});
for (const [packageName, usageData] of Object.entries(stats)) {
console.log(`${packageName}: ${usageData.totalTimeInForeground}ms`);
}

isUsageStatsPermissionGranted

isUsageStatsPermissionGrantedの概要

isUsageStatsPermissionGrantedの概要

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

使用状況の設定画面を開きます。 使用状況の設定画面が開き、ユーザーが使用状況の許可を付与することができます。 許可が既に付与されている場合でも、設定画面が常に開きます。

import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await CapacitorUsageStatsManager.openUsageStatsSettings();

すべてのインストール済みパッケージをデバイス上で検索します。 QUERY_ALL_PACKAGES許可が必要です。

import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { packages } = await CapacitorUsageStatsManager.queryAllPackages();
packages.forEach(pkg => {
console.log(`${pkg.appName} (${pkg.packageName}): v${pkg.versionName}`);
});

使用状況統計のクエリオプション

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 から続けてください。

あなたが使用している場合 Getting Started 計画ダッシュボードとAPIの運用を計画するには、接続する @capgo/capacitor-アンドロイド使用状況マネージャー Using @capgo/capacitor-android-usagestatsmanager API まとめ API Overview Introduction Introduction API キー API Keys デバイス __CAPGO_KEEP_0__ Keys