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

# Builder

*** ** * ** ***

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.app.usage.AppUsageDurationQuery.Builder](https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#) |

Builder for `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery`.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#Builder(kotlin.Long,%20kotlin.Long,%20kotlin.Int)(startTimeMillis: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html, endTimeMillis: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html, intervalType: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Constructor that specifies the period for which to return events. |

| Public methods ||
|---|---|
| [AppUsageDurationQuery](https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery) | `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#build()()` Builds a read-only `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery` object. |
| [AppUsageDurationQuery.Builder](https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#) | `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#setEndTimeMillis(kotlin.Long)(endTimeMillis: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` Sets the exclusive end timestamp. |
| [AppUsageDurationQuery.Builder](https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#) | `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#setIntervalType(kotlin.Int)(intervalType: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets the time interval by which the stats are aggregated. |
| [AppUsageDurationQuery.Builder](https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#) | `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#setStartTimeMillis(kotlin.Long)(startTimeMillis: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` Sets the inclusive start timestamp. |

## Public constructors

### Builder

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

```
Builder(
    startTimeMillis: Long, 
    endTimeMillis: Long, 
    intervalType: Int)
```

Constructor that specifies the period for which to return events.

| Parameters ||
|---|---|
| `startTimeMillis` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): inclusive start timestamp, as per `https://developer.android.com/reference/kotlin/java/lang/System.html#currentTimeMillis()` Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. |
| `endTimeMillis` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): exclusive end timestamp, as per `https://developer.android.com/reference/kotlin/java/lang/System.html#currentTimeMillis()` Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. |
| `intervalType` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): time interval by which the stats are aggregated. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_DAILY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_WEEKLY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_MONTHLY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_YEARLY:kotlin.Int` |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if `endTimeMillis` \< `startTimeMillis` or if `startTimeMillis` is negative, or if `intervalType` is invalid. |

## Public methods

### build

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

```
fun build(): AppUsageDurationQuery
```

Builds a read-only `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery` object.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery` | This value cannot be `null`. |

### setEndTimeMillis

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

```
fun setEndTimeMillis(endTimeMillis: Long): AppUsageDurationQuery.Builder
```

Sets the exclusive end timestamp.

| Parameters ||
|---|---|
| `endTimeMillis` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): exclusive end timestamp, as per `https://developer.android.com/reference/kotlin/java/lang/System.html#currentTimeMillis()` Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#` | this `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#` object. This value cannot be `null`. |

### setIntervalType

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

```
fun setIntervalType(intervalType: Int): AppUsageDurationQuery.Builder
```

Sets the time interval by which the stats are aggregated.

| Parameters ||
|---|---|
| `intervalType` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): time interval by which the stats are aggregated. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_DAILY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_WEEKLY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_MONTHLY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/usage/UsageStatsManager#INTERVAL_YEARLY:kotlin.Int` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#` | this `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#` object. This value cannot be `null`. |

### setStartTimeMillis

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

```
fun setStartTimeMillis(startTimeMillis: Long): AppUsageDurationQuery.Builder
```

Sets the inclusive start timestamp.

| Parameters ||
|---|---|
| `startTimeMillis` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): inclusive start timestamp, as per `https://developer.android.com/reference/kotlin/java/lang/System.html#currentTimeMillis()` Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#` | this `https://developer.android.com/reference/kotlin/android/app/usage/AppUsageDurationQuery.Builder#` object. This value cannot be `null`. |