Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/app/usage/UsageStatsManager#constants) \| [Methods](https://developer.android.com/reference/android/app/usage/UsageStatsManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/usage/UsageStatsManager#inhmethods)

# UsageStatsManager

*** ** * ** ***


`
public

final

class
UsageStatsManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.usage.UsageStatsManager |

<br />

*** ** * ** ***

Provides access to device usage history and statistics. Usage data is aggregated into
time intervals: days, weeks, months, and years.

<br />

When requesting usage data since a particular time, the request might look something like this:

```
PAST                   REQUEST_TIME                    TODAY                   FUTURE
\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014||\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014¦---|
                       YEAR ||                           ¦                       |
\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014||\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014¦---|
 MONTH            |         ||                MONTH      ¦                       |
\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014|\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014||\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014¦---|
  |      WEEK     |     WEEK||    |     WEEK     |     WE¦EK     |      WEEK     |
\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014||\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014|\u2014\u2014\u2014\u2014\u2014\u2014\u2014¦---|
                            ||           |DAY|DAY|DAY|DAY¦DAY|DAY|DAY|DAY|DAY|DAY|
\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014||\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014¦---|
```
A request for data in the middle of a time interval will include that interval.

<br />

**NOTE:** Most methods on this API require the permission android.permission.PACKAGE_USAGE_STATS. However, declaring the permission implies intention to use the API and the user of the device still needs to grant permission through the Settings application. See `https://developer.android.com/reference/android/provider/Settings#ACTION_USAGE_ACCESS_SETTINGS`. Methods which only return the information for the calling package do not require this permission. E.g. `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()` and `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEventsForSelf(long,%20long)`.

<br />

## Summary

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#EXTRA_EVENT_ACTION` A String extra, when used with `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#getExtras()`, that indicates the action of the user interaction associated with the event. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#EXTRA_EVENT_CATEGORY` A String extra, when used with `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#getExtras()`, that indicates the category of the user interaction associated with the event. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_BEST` An interval type that will use the best fit interval for the given time range. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_DAILY` An interval type that spans a day. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_MONTHLY` An interval type that spans a month. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_WEEKLY` An interval type that spans a week. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_YEARLY` An interval type that spans a year. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` The app was used very recently, currently in use or likely to be used very soon. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_FREQUENT` The app was used in the last few days and/or likely to be used in the next few days. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_RARE` The app has not be used for several days and/or is unlikely to be used for several days. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_RESTRICTED` The app has not be used for several days, is unlikely to be used for several days, and has been misbehaving in some manner. |
| `int` | `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_WORKING_SET` The app was used recently and/or likely to be used in the next few hours. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()() ` Returns the current standby bucket of the calling app. |
| ` boolean` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#isAppInactive(java.lang.String)(https://developer.android.com/reference/java/lang/String packageName) ` Returns whether the specified app is currently considered inactive. |
| ` https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/android/app/usage/UsageStats>` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryAndAggregateUsageStats(long,%20long)(long beginTime, long endTime) ` A convenience method that queries for all stats in the given range (using the best interval for that range), merges the resulting data, and keys it by package name. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/AppUsageDuration>` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryAppUsageDuration(android.app.usage.AppUsageDurationQuery)(https://developer.android.com/reference/android/app/usage/AppUsageDurationQuery query) ` Gets application usage stats for the given time range, aggregated by the specified interval. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/ConfigurationStats>` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryConfigurations(int,%20long,%20long)(int intervalType, long beginTime, long endTime) ` Gets the hardware configurations the device was in for the given time range, aggregated by the specified interval. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/EventStats>` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEventStats(int,%20long,%20long)(int intervalType, long beginTime, long endTime) ` Gets aggregated event stats for the given time range, aggregated by the specified interval. |
| ` https://developer.android.com/reference/android/app/usage/UsageEvents` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEvents(long,%20long)(long beginTime, long endTime) ` Query for events in the given time range. |
| ` https://developer.android.com/reference/android/app/usage/UsageEvents` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEvents(android.app.usage.UsageEventsQuery)(https://developer.android.com/reference/android/app/usage/UsageEventsQuery query) ` Query for events with specific UsageEventsQuery object. |
| ` https://developer.android.com/reference/android/app/usage/UsageEvents` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEventsForSelf(long,%20long)(long beginTime, long endTime) ` Like `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEvents(long,%20long)`, but only returns events for the calling package. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/UsageStats>` | ` https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)(int intervalType, long beginTime, long endTime) ` Gets application usage stats for the given time range, aggregated by the specified interval. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Constants

### EXTRA_EVENT_ACTION

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String EXTRA_EVENT_ACTION
```

A String extra, when used with `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#getExtras()`, that indicates
the action of the user interaction associated with the event. The action cannot be
more than 127 characters, longer value will be truncated to 127 characters.

<br />

Constant Value:

"android.app.usage.extra.EVENT_ACTION"


### EXTRA_EVENT_CATEGORY

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String EXTRA_EVENT_CATEGORY
```

A String extra, when used with `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#getExtras()`, that indicates
the category of the user interaction associated with the event. The category cannot
be more than 127 characters, longer value will be truncated to 127 characters.

<br />

Constant Value:

"android.app.usage.extra.EVENT_CATEGORY"


### INTERVAL_BEST

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int INTERVAL_BEST
```

An interval type that will use the best fit interval for the given time range.
See `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.

<br />

Constant Value:

4
(0x00000004)


### INTERVAL_DAILY

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int INTERVAL_DAILY
```

An interval type that spans a day. See `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.

<br />

Constant Value:

0
(0x00000000)


### INTERVAL_MONTHLY

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int INTERVAL_MONTHLY
```

An interval type that spans a month. See `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.

<br />

Constant Value:

2
(0x00000002)


### INTERVAL_WEEKLY

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int INTERVAL_WEEKLY
```

An interval type that spans a week. See `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.

<br />

Constant Value:

1
(0x00000001)


### INTERVAL_YEARLY

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int INTERVAL_YEARLY
```

An interval type that spans a year. See `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.

<br />

Constant Value:

3
(0x00000003)


### STANDBY_BUCKET_ACTIVE

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STANDBY_BUCKET_ACTIVE
```

The app was used very recently, currently in use or likely to be used very soon. Standby
bucket values that are ≤ `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` will not be throttled by the
system while they are in this bucket. Buckets \> `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` will most
likely be restricted in some way. For instance, jobs and alarms may be deferred.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()`

Constant Value:

10
(0x0000000a)


### STANDBY_BUCKET_FREQUENT

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STANDBY_BUCKET_FREQUENT
```

The app was used in the last few days and/or likely to be used in the next few days.
Restrictions will apply to these apps, such as deferral of jobs and alarms. The delays may be
greater than for apps in higher buckets (lower bucket value). Bucket values \>
`https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_FREQUENT` may additionally have network access limited.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()`

Constant Value:

30
(0x0000001e)


### STANDBY_BUCKET_RARE

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STANDBY_BUCKET_RARE
```

The app has not be used for several days and/or is unlikely to be used for several days.
Apps in this bucket will have more restrictions, including network restrictions, except
during certain short periods (at a minimum, once a day) when they are allowed to execute
jobs, access the network, etc.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()`

Constant Value:

40
(0x00000028)


### STANDBY_BUCKET_RESTRICTED

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STANDBY_BUCKET_RESTRICTED
```

The app has not be used for several days, is unlikely to be used for several days, and has
been misbehaving in some manner.
Apps in this bucket will have the most restrictions, including network restrictions and
additional restrictions on jobs.

Note: this bucket is not enabled in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()`

Constant Value:

45
(0x0000002d)


### STANDBY_BUCKET_WORKING_SET

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STANDBY_BUCKET_WORKING_SET
```

The app was used recently and/or likely to be used in the next few hours. Restrictions will
apply to these apps, such as deferral of jobs and alarms.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()`

Constant Value:

20
(0x00000014)


## Public methods

### getAppStandbyBucket

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getAppStandbyBucket ()
```

Returns the current standby bucket of the calling app. The system determines the standby
state of the app based on app usage patterns. Standby buckets determine how much an app will
be restricted from running background tasks such as jobs and alarms.

Restrictions increase progressively from `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` to
`https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_RESTRICTED`, with `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` being the least
restrictive. The battery level of the device might also affect the restrictions.

Apps in buckets ≤ `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` have no standby restrictions imposed.
Apps in buckets \> `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_FREQUENT` may have network access restricted when
running in the background.

The standby state of an app can change at any time either due to a user interaction or a
system interaction or some algorithm determining that the app can be restricted for a period
of time before the user has a need for it.

You can also query the recent history of standby bucket changes by calling
`https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEventsForSelf(long,%20long)` and searching for
`https://developer.android.com/reference/android/app/usage/UsageEvents.Event#STANDBY_BUCKET_CHANGED`.

<br />

| Returns ||
|---|---|
| `int` | the current standby bucket of the calling app. One of STANDBY_BUCKET_\* constants. Value is one of the following: - `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_ACTIVE` - `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_WORKING_SET` - `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_FREQUENT` - `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_RARE` - `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_RESTRICTED` |

### isAppInactive

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isAppInactive (String packageName)
```

Returns whether the specified app is currently considered inactive. This will be true if the
app hasn't been used directly or indirectly for a period of time defined by the system. This
could be of the order of several hours or days. Apps are not considered inactive when the
device is charging.

The caller must have `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS` to query the
inactive state of other apps

<br />

<br />

| Parameters ||
|---|---|
| `packageName` | `String`: The package name of the app to query <br /> |

| Returns ||
|---|---|
| `boolean` | whether the app is currently considered inactive or false if querying another app without `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS` <br /> |

### queryAndAggregateUsageStats

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Map<String, UsageStats> queryAndAggregateUsageStats (long beginTime, 
                long endTime)
```

A convenience method that queries for all stats in the given range (using the best interval
for that range), merges the resulting data, and keys it by package name.
See `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.


Requires `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`

<br />

| Parameters ||
|---|---|
| `beginTime` | `long`: The inclusive beginning of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: The exclusive end of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/android/app/usage/UsageStats>` | A `https://developer.android.com/reference/java/util/Map` keyed by package name <br /> |

### queryAppUsageDuration

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public List<AppUsageDuration> queryAppUsageDuration (AppUsageDurationQuery query)
```

Gets application usage stats for the given time range, aggregated by the specified interval.

The usage statistics are pre-aggregated internally into calendar-aligned boundaries (e.g.,
for `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_DAILY`, a day is defined as midnight to midnight local time). The
returned list will only contain apps that have been used in this time range.

The returned list will contain one or more `https://developer.android.com/reference/android/app/usage/AppUsageDuration` objects for each
package, with usage data aggregated within each interval bucket that falls within the time
range between `https://developer.android.com/reference/android/app/usage/AppUsageDurationQuery#getStartTimeMillis()` and `https://developer.android.com/reference/android/app/usage/AppUsageDurationQuery#getEndTimeMillis()`, which may include the expanded interval periods
as described above.

Data can only be queried for the past 30 days. Queries for longer time ranges will
return an empty list.


Requires `https://developer.android.com/reference/android/Manifest.permission#QUERY_APP_USAGE`

<br />

| Parameters ||
|---|---|
| `query` | `AppUsageDurationQuery`: the `https://developer.android.com/reference/android/app/usage/AppUsageDurationQuery` used to specify the query parameters. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/AppUsageDuration>` | a list of `https://developer.android.com/reference/android/app/usage/AppUsageDuration` for each app used for the given time interval. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if the caller doesn't hold the `https://developer.android.com/reference/android/Manifest.permission#QUERY_APP_USAGE` permission |

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_DAILY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_WEEKLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_MONTHLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_YEARLY`

### queryConfigurations

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<ConfigurationStats> queryConfigurations (int intervalType, 
                long beginTime, 
                long endTime)
```

Gets the hardware configurations the device was in for the given time range, aggregated by
the specified interval. The results are ordered as in
`https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryUsageStats(int,%20long,%20long)`.

*Note: Starting from `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, if the user's
device is not in an unlocked state (as defined by `https://developer.android.com/reference/android/os/UserManager#isUserUnlocked()`),
then `null` will be returned.* .


Requires `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`

<br />

| Parameters ||
|---|---|
| `intervalType` | `int`: The time interval by which the stats are aggregated. <br /> |
| `beginTime` | `long`: The inclusive beginning of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: The exclusive end of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/ConfigurationStats>` | A list of `https://developer.android.com/reference/android/app/usage/ConfigurationStats` <br /> |

### queryEventStats

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<EventStats> queryEventStats (int intervalType, 
                long beginTime, 
                long endTime)
```

Gets aggregated event stats for the given time range, aggregated by the specified interval.

The returned list will contain a `https://developer.android.com/reference/android/app/usage/EventStats` object for each event type that
is being aggregated and has data for an interval that is a subset of the time range given.

The current event types that will be aggregated here are:

- `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#SCREEN_INTERACTIVE`
- `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#SCREEN_NON_INTERACTIVE`
- `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#KEYGUARD_SHOWN`
- `https://developer.android.com/reference/android/app/usage/UsageEvents.Event#KEYGUARD_HIDDEN`

*Note: Starting from `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, if the user's
device is not in an unlocked state (as defined by `https://developer.android.com/reference/android/os/UserManager#isUserUnlocked()`),
then `null` will be returned.* .   
Requires `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`

<br />

<br />

| Parameters ||
|---|---|
| `intervalType` | `int`: The time interval by which the stats are aggregated. <br /> |
| `beginTime` | `long`: The inclusive beginning of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: The exclusive end of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/EventStats>` | A list of `https://developer.android.com/reference/android/app/usage/EventStats` <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_DAILY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_WEEKLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_MONTHLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_YEARLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_BEST`

### queryEvents

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UsageEvents queryEvents (long beginTime, 
                long endTime)
```

Query for events in the given time range. Events are only kept by the system for a few
days.

*Note: Starting from `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, if the user's
device is not in an unlocked state (as defined by `https://developer.android.com/reference/android/os/UserManager#isUserUnlocked()`),
then `null` will be returned.* .


Requires `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`

<br />

| Parameters ||
|---|---|
| `beginTime` | `long`: The inclusive beginning of the range of events to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: The exclusive end of the range of events to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/UsageEvents` | A `https://developer.android.com/reference/android/app/usage/UsageEvents`. <br /> |

### queryEvents

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UsageEvents queryEvents (UsageEventsQuery query)
```

Query for events with specific UsageEventsQuery object.

*Note: if the user's device is not in an unlocked state (as defined by
`https://developer.android.com/reference/android/os/UserManager#isUserUnlocked()`), then `null` will be returned.* .


Requires `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`

<br />

| Parameters ||
|---|---|
| `query` | `UsageEventsQuery`: The query object used to specify the query parameters. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/UsageEvents` | A `https://developer.android.com/reference/android/app/usage/UsageEvents` which contains the events matching the query parameters. <br /> |

### queryEventsForSelf

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UsageEvents queryEventsForSelf (long beginTime, 
                long endTime)
```

Like `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEvents(long,%20long)`, but only returns events for the calling package.
*Note: Starting from `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, if the user's
device is not in an unlocked state (as defined by `https://developer.android.com/reference/android/os/UserManager#isUserUnlocked()`),
then `null` will be returned.*

<br />

| Parameters ||
|---|---|
| `beginTime` | `long`: The inclusive beginning of the range of events to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: The exclusive end of the range of events to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/UsageEvents` | A `https://developer.android.com/reference/android/app/usage/UsageEvents` object. <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#queryEvents(long,%20long)`

### queryUsageStats

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<UsageStats> queryUsageStats (int intervalType, 
                long beginTime, 
                long endTime)
```

Gets application usage stats for the given time range, aggregated by the specified interval.


The returned list will contain one or more `https://developer.android.com/reference/android/app/usage/UsageStats` objects for each package, with
usage data that covers at least the given time range.
Note: The begin and end times of the time range may be expanded to the nearest whole interval
period.
*Note: Starting from `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, if the user's
device is not in an unlocked state (as defined by `https://developer.android.com/reference/android/os/UserManager#isUserUnlocked()`),
then `null` will be returned.* .   
Requires `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`

<br />

<br />

| Parameters ||
|---|---|
| `intervalType` | `int`: The time interval by which the stats are aggregated. <br /> |
| `beginTime` | `long`: The inclusive beginning of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: The exclusive end of the range of stats to include in the results. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/usage/UsageStats>` | A list of `https://developer.android.com/reference/android/app/usage/UsageStats` <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_DAILY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_WEEKLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_MONTHLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_YEARLY`
- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#INTERVAL_BEST`