Getting Started
Copia un prompt di configurazione con i passaggi di installazione e la guida markdown completa per questo plugin.
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.
Installa
Sezione intitolata “Installa”Puoi utilizzare la nostra configurazione assistita dall'IA per installare il plugin. Aggiungi le Capgo competenze al tuo strumento di AI utilizzando il seguente comando:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsPoi utilizza il seguente prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-android-usagestatsmanager` plugin in my project.Se preferisci l'installazione manuale, installa il plugin eseguendo i seguenti comandi e segui le istruzioni specifiche per la piattaforma riportate di seguito:
bun add @capgo/capacitor-android-usagestatsmanagerbunx cap syncImporta
Sezione intitolata “Importa”import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';API Panoramica
Sezione intitolata “API Panoramica”queryAndAggregateUsageStats
Sezione intitolata “queryAndAggregateUsageStats”Query e aggrega i dati di utilizzo per l'intervallo di tempo specificato.
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
Sezione intitolata “isUsageStatsPermissionGranted”Verifica se è concesso il permesso per le statistiche di utilizzo.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await CapacitorUsageStatsManager.isUsageStatsPermissionGranted();if (!granted) { await CapacitorUsageStatsManager.openUsageStatsSettings();}openUsageStatsSettings
Sezione intitolata “openUsageStatsSettings”Apre la schermata di impostazioni delle statistiche di utilizzo. Questa aprirà la schermata di impostazioni delle statistiche di utilizzo, che consente all'utente di concedere il permesso per le statistiche di utilizzo. Questa aprirà sempre la schermata di impostazioni, anche se il permesso è già stato concesso.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await CapacitorUsageStatsManager.openUsageStatsSettings();queryAllPackages
Sezione intitolata “queryAllPackages”Query tutte le applicazioni installate sul dispositivo. Richiede il permesso di 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}`);});Tipo di Riferimento
Sezione intitolata “Tipo di Riferimento”UsageStatsOptions
Sezione intitolata “UsageStatsOptions”Opzioni per la query delle statistiche di utilizzo.
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;}Statistiche di utilizzo per un'app 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
Section titled “UsageStatsPermissionResult”Risultato di una verifica delle statistiche di utilizzo.
export interface UsageStatsPermissionResult { /** * Whether the usage stats permission is granted. */ granted: boolean;}Rappresenta le informazioni base di un pacchetto installato.
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;}Fonte di verità
Sezione intitolata “Fonte di Verità”Questa pagina è generata dal plugin’s src/definitions.tsRiepiloga quando le informazioni pubbliche API cambiano in modo upstream.
Keep going from Getting Started
Sezione intitolata “Continua da Iniziare”Se stai utilizzando Getting Started per pianificare il dashboard e le API operazioni, connettilo con Utilizzando @capgo/capacitor-android-usagestatsmanager per la capacità nativa in Utilizzando @capgo/capacitor-android-usagestatsmanager, API Overview per i dettagli di implementazione in API Overview, Introduzione per i dettagli di implementazione in Introduzione, API Chiavi per i dettagli di implementazione in API Chiavi, e Dispositivi Per i dettagli di implementazione nei dispositivi.