시작하기
설치
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페이지/영역: Capgo 마케팅 웹사이트. 역할: UI 레이블. 표시되는 곳: page agents/[slug].astro. 메시지 키 `agents_page_copy_label` (Agents Page Copy Label).
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-usagestatsmanagerbunx cap sync수입
수입import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';API 개요
API 개요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
사용 통계 허용 여부를 확인합니다.사용 통계 쿼리 및 집계
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await CapacitorUsageStatsManager.isUsageStatsPermissionGranted();if (!granted) { await CapacitorUsageStatsManager.openUsageStatsSettings();}openUsageStatsSettings
사용 통계 설정 열기사용 통계 설정 화면을 열어 주세요. 사용자에게 사용 통계 허용 권한을 부여할 수 있는 화면을 열어 주세요. 권한이 이미 부여된 경우에도 항상 설정 화면을 열어 주세요.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await CapacitorUsageStatsManager.openUsageStatsSettings();queryAllPackages
설치된 모든 패키지를 디바이스에서 쿼리합니다.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}`);});타입 참조
사용 통계 옵션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
사용 통계안드로이드 앱의 사용 통계
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
사용 통계 권한 결과패키지 정보
export interface UsageStatsPermissionResult { /** * Whether the usage stats permission is granted. */ granted: boolean;}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;}이 페이지는 플러그인의
Source Of Truth이 페이지는 플러그인의 src/definitions.ts. API를 업스트림에서 변경하면 다시 싱크를 실행하세요.
Getting Started에서 계속 진행하세요.
Getting Started에서 계속 진행하세요.Getting Started를 사용하여 대시보드와 __CAPGO_KEEP_0__를 계획하고 운영하려면 __CAPGO_KEEP_0__를 연결하세요. Getting Started 계획 대시보드와 API 작업을 계획하고 싶으시다면, @capgo/capacitor-안드로이드 사용 통계 관리자 native 기능을 사용하는 @capgo/capacitor-android-usagestatsmanager에 대한 native 기능 API 개요 API 개요 소개 __CAPGO_KEEP_0__ API 키 API 구현 세부 정보에 대한 키 기기 __CAPGO_KEEP_0__ 구현 세부 정보에 대한 기기