Inizia a utilizzare
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.
Installazione
Sezione intitolata “Installazione”Puoi utilizzare la nostra configurazione assistita da AI per installare il plugin. Aggiungi le Capgo competenze al tuo strumento AI utilizzando il seguente comando:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsPoi utilizza la seguente richiesta:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-android-usagestatsmanager` plugin in my project.Se preferisci la configurazione Manuale, installa il plugin eseguendo i seguenti comandi e segui le istruzioni specifiche del tuo platform:
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”Esegue query e aggrega le statistiche di utilizzo per il range 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 UsageStatsManager.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 UsageStatsManager.isUsageStatsPermissionGranted();if (!granted) { await UsageStatsManager.openUsageStatsSettings();}openUsageStatsSettings
Sezione intitolata “apriImpostazioniUtilizzo”Apre la schermata delle impostazioni delle statistiche di utilizzo. Questa azione aprirà la schermata delle impostazioni delle statistiche di utilizzo, che consente all'utente di concedere il permesso per le statistiche di utilizzo. Questa azione aprirà sempre la schermata delle impostazioni, anche se il permesso è già stato concesso.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await UsageStatsManager.openUsageStatsSettings();queryAllPackages
Sezione intitolata “queryAllPackages”Cerca tutti i pacchetti installati sul dispositivo. Richiede la autorizzazione 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}`);});Riferimento di tipo
Sezione intitolata “Type Reference”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;}UsageStats
Sezione intitolata “UsageStats”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
Sezione intitolata “Risultato della verifica delle statistiche di utilizzo”Risultato della 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 e src/definitions.tsRiavvia la sincronizzazione quando le informazioni pubbliche API cambiano nell'area upstream.
Continua da Iniziare
Sezione intitolata “Continua da Iniziare”Se stai utilizzando Iniziare per pianificare il dashboard e le operazioni API, connettilo con Utilizzare @capgo/capacitor-android-usagestatsmanager for the native capability in Using @capgo/capacitor-android-usagestatsmanager, Per i dettagli di implementazione in Panoramica di API, for the implementation detail in API Overview, Per i dettagli di implementazione in Introduzione, __CAPGO_KEEP_0__ Chiavi Per i dettagli di implementazione in API Chiavi, e for the implementation detail in API Keys, and Getting Started per i dettagli di implementazione in dispositivi.