Démarrage
Copier un prompt de configuration avec les étapes d'installation et la guide markdown complète 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 “Installer”bun add @capgo/capacitor-android-usagestatsmanagerbunx cap syncImporter
Section intitulée “Importer”import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';API Vue d'ensemble
Section intitulée “API Vue d'ensemble”queryAndAggregateUsageStats
Section intitulée “queryAndAggregateUsageStats”Effectue des requêtes et agrège les statistiques d'utilisation pour la plage de temps donnée.
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
Section intitulée “isUsageStatsPermissionGranted”Vérifie si la permission d'utilisation des statistiques est accordée.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await UsageStatsManager.isUsageStatsPermissionGranted();if (!granted) { await UsageStatsManager.openUsageStatsSettings();}openUsageStatsSettings
Section intitulée “openUsageStatsSettings”Ouvrez l'écran de paramètres des statistiques d'utilisation.
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await UsageStatsManager.openUsageStatsSettings();queryAllPackages
Cela ouvrira toujours l'écran de paramètres, même si la permission est déjà accordée.Copier dans le presse-papier
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { packages } = await UsageStatsManager.queryAllPackages();packages.forEach(pkg => { console.log(`${pkg.appName} (${pkg.packageName}): v${pkg.versionName}`);});Interroge toutes les packages installés sur le appareil.
Exige la permission QUERY_ALL_PACKAGES.UsageStatsOptions
Copier dans le presse-papierRéférence de type
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 “UsageStatsOptions”Options pour interroger les statistiques d'utilisation.
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 « Résultat de la vérification des autorisations d'utilisation des statistiques »Résultat d'une vérification des autorisations d'utilisation des statistiques.
export interface UsageStatsPermissionResult { /** * Whether the usage stats permission is granted. */ granted: boolean;}Représente les informations de base sur 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 du plugin, src/definitions.tsRe-run la synchronisation lorsque les modifications publiques API sont mises à jour en amont.