Saltare al contenuto

Inizia a utilizzare

GitHub

Puoi utilizzare la nostra configurazione assistita da AI per installare il plugin. Aggiungi le Capgo competenze al tuo strumento AI utilizzando il seguente comando:

Finestra del terminale
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Poi 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:

Finestra del terminale
bun add @capgo/capacitor-android-usagestatsmanager
bunx cap sync
import { CapacitorUsageStatsManager } from '@capgo/capacitor-android-usagestatsmanager';

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

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

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();

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

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

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

Questa pagina è generata dal plugin e src/definitions.tsRiavvia la sincronizzazione quando le informazioni pubbliche API cambiano nell'area upstream.

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.