https://github.com/Cap-go/capacitor-android-usagestatsmanager
https://github.com/Cap-go/capacitor-android-usagestatsmanager
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/Cap-go/capacitor-android-usagestatsmanager
- Owner: Cap-go
- Created: 2025-04-08T02:22:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-11T09:51:13.000Z (about 1 year ago)
- Last Synced: 2025-05-31T05:56:09.974Z (about 1 year ago)
- Language: Java
- Size: 604 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
- awesome-ionic - capacitor-android-usagestatsmanager - Exposes the Android's UsageStatsManager SDK to Capacitor. (Capgo Capacitor Plugins)
- awesome-capacitor - Usage Stats Manager - Exposes the Android's UsageStatsManager SDK. ([Capgo plugins](https://capgo.app/) / Android Specific)
README
# @capgo/capacitor-android-usagestatsmanager

➡️ Get Instant updates for your App with Capgo 🚀
Fix your annoying bug now, Hire a Capacitor expert 💪
## Description
Exposes the Android's UsageStatsManager SDK to Capacitor
## Usage
Requires the following permissions in your `AndroidManifest.xml`:
```xml
```
## Install
```bash
npm install @capgo/capacitor-android-usagestatsmanager
npx cap sync
```
## API
* [`queryAndAggregateUsageStats(...)`](#queryandaggregateusagestats)
* [`isUsageStatsPermissionGranted()`](#isusagestatspermissiongranted)
* [`openUsageStatsSettings()`](#openusagestatssettings)
* [`queryAllPackages()`](#queryallpackages)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
### queryAndAggregateUsageStats(...)
```typescript
queryAndAggregateUsageStats(options: UsageStatsOptions) => Promise>
```
Queries and aggregates usage stats for the given options.
| Param | Type | Description |
| ------------- | --------------------------------------------------------------- | ---------------------------- |
| **`options`** | UsageStatsOptions | - The options for the query. |
**Returns:** Promise<Record<string, UsageStats>>
--------------------
### isUsageStatsPermissionGranted()
```typescript
isUsageStatsPermissionGranted() => Promise
```
Checks if the usage stats permission is granted.
**Returns:** Promise<UsageStatsPermissionResult>
--------------------
### openUsageStatsSettings()
```typescript
openUsageStatsSettings() => Promise
```
Open the usage stats settings screen.
This will open the usage stats settings screen, which allows the user to grant the usage stats permission.
This will always open the settings screen, even if the permission is already granted.
--------------------
### queryAllPackages()
```typescript
queryAllPackages() => Promise<{ packages: PackageInfo[]; }>
```
Queries all installed packages on the device.
Requires the QUERY_ALL_PACKAGES permission.
**Returns:** Promise<{ packages: PackageInfo[]; }>
**Since:** 1.2.0
--------------------
### Interfaces
#### UsageStats
| Prop | Type | Description |
| ----------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------- |
| **`firstTimeStamp`** | number | The first timestamp of the usage stats. |
| **`lastTimeStamp`** | number | The last timestamp of the usage stats. |
| **`lastTimeForegroundServiceUsed`** | number | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
| **`lastTimeUsed`** | number | The last time the app was used. |
| **`lastTimeVisible`** | number | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
| **`packageName`** | string | The name of the package. |
| **`totalForegroundServiceUsed`** | number | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
| **`totalTimeInForeground`** | number | The total time the app was in the foreground. |
| **`totalTimeVisible`** | number | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
#### UsageStatsOptions
| Prop | Type | Description |
| --------------- | ------------------- | -------------------------------------------------------------------------------------------------------- |
| **`beginTime`** | number | The inclusive beginning of the range of stats to include in the results. Defined in terms of "Unix time" |
| **`endTime`** | number | The exclusive end of the range of stats to include in the results. Defined in terms of "Unix time" |
#### UsageStatsPermissionResult
| Prop | Type | Description |
| ------------- | -------------------- | ---------------------------------------------- |
| **`granted`** | boolean | Whether the usage stats permission is granted. |
#### PackageInfo
Represents basic information about an installed package.
| Prop | Type |
| ---------------------- | ------------------- |
| **`packageName`** | string |
| **`appName`** | string |
| **`versionName`** | string |
| **`versionCode`** | number |
| **`firstInstallTime`** | number |
| **`lastUpdateTime`** | number |
### Type Aliases
#### Record
Construct a type with a set of properties K of type T
{
[P in K]: T;
}