Prise en main
Copiez un prompt de configuration incluant les étapes d'installation et le guide markdown complet pour ce 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.
Installer
Section intitulée « Installation »Vous pouvez utiliser notre configuration assistée par IA pour installer le plugin. Ajoutez les skills Capgo à votre outil d'IA avec la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite le prompt suivant :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-android-usagestatsmanager` plugin in my project.Si vous préférez une installation manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à chaque plateforme ci-dessous :
bun add @capgo/capacitor-android-usagestatsmanagernpx cap syncImporter
Section intitulée « Import »import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';Démarrage rapide
Section intitulée « Démarrage rapide »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, packageName: 'com.example.app',});
for (const [packageName, usageData] of Object.entries(stats)) { console.log(`${packageName}: ${usageData.totalTimeInForeground}ms`);}Exemple : queryUsageStats
Section intitulée « Exemple : queryUsageStats »import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const startOfDay = new Date().setHours(0, 0, 0, 0);const { stats } = await CapacitorUsageStatsManager.queryUsageStats({ intervalType: 0, // INTERVAL_DAILY beginTime: startOfDay, endTime: Date.now(), packageName: 'com.example.app',});stats.forEach((bucket) => { console.log(`${bucket.packageName}: ${bucket.totalTimeInForeground}ms`);});Exemple : queryEvents
Section intitulée « Exemple : queryEvents »import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const startOfDay = new Date().setHours(0, 0, 0, 0);const { events } = await CapacitorUsageStatsManager.queryEvents({ beginTime: startOfDay, endTime: Date.now(), packageName: 'com.example.app',});events.forEach((event) => { console.log(`${event.packageName} type=${event.eventType} at ${event.timeStamp}`);});Erreurs courantes
Section intitulée « Erreurs courantes »- Sync native : exécuter
npx cap syncaprès les mises à jour du plugin. - Source de vérité : fiez-vous
src/definitions.tsau repo GitHub.
Aperçu de API
Section intitulée « Aperçu API »queryAndAggregateUsageStats
Section intitulée « queryAndAggregateUsageStats »Interroge et agrège les statistiques d'utilisation sur la période donnée.
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
Section intitulée « isUsageStatsPermissionGranted »Vérifie si la permission des statistiques d'utilisation est accordée.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await CapacitorUsageStatsManager.isUsageStatsPermissionGranted();if (!granted) { await CapacitorUsageStatsManager.openUsageStatsSettings();}openUsageStatsSettings
Section intitulée « openUsageStatsSettings »Ouvrir l'écran des paramètres d'utilisation des statistiques. Cela ouvrira l'écran des paramètres d'utilisation des statistiques, permettant à l'utilisateur d'accorder la permission d'accès aux statistiques d'utilisation. Cela ouvrira systématiquement l'écran des paramètres, même si la permission est déjà accordée.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await CapacitorUsageStatsManager.openUsageStatsSettings();queryAllPackages
Section intitulée « queryAllPackages »Interroge tous les packages installés sur l'appareil. Nécessite la permission 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}`);});Référence de type
Section intitulée « Référence de type »UsageStatsOptions
Section intitulée « UsageStatsOptions »Options pour interroger les statistiques d'utilisation.
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
Section intitulée « UsageStats »Usage statistics for an Android app.
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 intitulée « UsageStatsPermissionResult »Résultat d'une vérification de la permission usage stats.
export interface UsageStatsPermissionResult { /** * Whether the usage stats permission is granted. */ granted: boolean;}PackageInfo
Section intitulée « PackageInfo »Représente les informations de base d'un package installé.
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 de vérité
Section intitulée « Source de vérité »Cette page est générée à partir de src/definitions.ts. Relancez la synchronisation lorsque l’API public change en amont.
Continuer depuis Getting Started
Section intitulée « Continuer après Prise en main »Si vous utilisez Prise en main pour planifier les opérations du dashboard et de API, connectez-l’avec Utiliser @capgo/capacitor-android-usagestatsmanager pour la fonctionnalité native dans Utiliser @capgo/capacitor-android-usagestatsmanager, Aperçu de API pour les détails d'implémentation dans « Vue d'ensemble de API », Introduction pour les détails d'implémentation dans l'introduction, Clés API pour les détails d'implémentation dans « Clés API », et Appareils pour les détails d'implémentation dans Devices.