Passer au contenu

Prise en main

GitHub

Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA à l'aide de la commande suivante :

Fenêtre de terminal
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Ensuite, utilisez la prompt suivante :

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 la configuration manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :

Fenêtre de terminal
bun add @capgo/capacitor-android-usagestatsmanager
bunx cap sync
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';

Récupère 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`);
}

Vérifie si le permis d'accès aux statistiques d'utilisation est accordé.

import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
const { granted } = await UsageStatsManager.isUsageStatsPermissionGranted();
if (!granted) {
await UsageStatsManager.openUsageStatsSettings();
}

Ouvrez l'écran de paramètres des statistiques d'utilisation.

import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';
await UsageStatsManager.openUsageStatsSettings();

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}`);
});

Section intitulée « Référence de type »

Section intitulée « Options de statistiques d'utilisation »

Copier dans le presse-papier

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;
}

Section intitulée « Options de 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;
}

Résultat d'une vérification de la permission 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;
}

Cette page est générée à partir du plugin’s src/definitions.tsRe-run la synchronisation lorsque les modifications publiques API changent en amont.

Continuez de la section « Getting Started »

Section intitulée « Continuez de l'Accueil »

Si vous utilisez Accueil pour planifier le tableau de bord et les opérations API Using @capgo/capacitor-android-usagestatsmanager Utilisation de @capgo/capacitor-android-usagestatsmanager pour la capacité native dans Utilisation de @API/__CAPGO_KEEP_1__-android-usagestatsmanager API Vue d'ensemble pour le détail d'implémentation dans __CAPGO_KEEP_0__ Vue d'ensemble Introduction API Keys API Clés Appareils pour le détail d'implémentation dans Appareils.