# WorkMetricsQuery.Builder

Artifact: [androidx.work:work-analytics](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/analytics/WorkMetricsQuery.kt+class:androidx.work.analytics.WorkMetricsQuery.Builder) Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

*** ** * ** ***


```
public final class WorkMetricsQuery.Builder
```

<br />

*** ** * ** ***

A builder for `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#Builder()()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addStates(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State> states)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State`s to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addStates(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State... states)` Adds `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State`s to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addTags(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of tags to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addTags(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... tags)` Adds tags to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addWorkIds(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html> workIds)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` `workIds` to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addWorkIds(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html... workIds)` Adds `https://developer.android.com/reference/androidx/work/WorkRequest` `workIds` to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addWorkerClassNames(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> workerClassNames)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of worker class names to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#addWorkerClassNames(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... workerClassNames)` Adds worker class names to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#build()()` Creates an instance of `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#setBeginTimeMillis(kotlin.Long)(long beginTimeMillis)` Sets the start of the enqueue time range to filter the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder#setEndTimeMillis(kotlin.Long)(long endTimeMillis)` Sets the end of the enqueue time range to filter the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`. |

## Public constructors

### Builder

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public Builder()
```

## Public methods

### addStates

```
public final @NonNull WorkMetricsQuery.Builder addStates(@NonNull List<@NonNull WorkMetricsInfo.State> states)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State`s to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State> states` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State`s to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addStates

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addStates(@NonNull WorkMetricsInfo.State... states)
```

Adds `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State`s to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State... states` | The `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State`s to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addTags

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addTags(@NonNull List<@NonNull String> tags)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of tags to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of tags to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addTags

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addTags(@NonNull String... tags)
```

Adds tags to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... tags` | The tags to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addWorkIds

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addWorkIds(@NonNull List<@NonNull UUID> workIds)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` `workIds` to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html> workIds` | The `https://developer.android.com/reference/androidx/work/WorkRequest` `workIds` to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addWorkIds

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addWorkIds(@NonNull UUID... workIds)
```

Adds `https://developer.android.com/reference/androidx/work/WorkRequest` `workIds` to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html... workIds` | The `https://developer.android.com/reference/androidx/work/WorkRequest` `workIds` to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addWorkerClassNames

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addWorkerClassNames(@NonNull List<@NonNull String> workerClassNames)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of worker class names to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> workerClassNames` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of worker class names to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### addWorkerClassNames

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder addWorkerClassNames(@NonNull String... workerClassNames)
```

Adds worker class names to the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... workerClassNames` | The worker class names to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### build

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery build()
```

Creates an instance of `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery` | the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery` instance |

### setBeginTimeMillis

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder setBeginTimeMillis(long beginTimeMillis)
```

Sets the start of the enqueue time range to filter the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `long beginTimeMillis` | The start of the time range (inclusive), in milliseconds since epoch (e.g. `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()`). |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |

### setEndTimeMillis

Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

```
public final @NonNull WorkMetricsQuery.Builder setEndTimeMillis(long endTimeMillis)
```

Sets the end of the enqueue time range to filter the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery`.

| Parameters |
|---|---|
| `long endTimeMillis` | The end of the time range (inclusive), in milliseconds since epoch (e.g. `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()`). |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsQuery.Builder` |