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

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/net/Uri.Builder "View this page in Java")

```
class Builder
```

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

Helper class for building or manipulating URI references. Not safe for concurrent use.

An absolute hierarchical URI reference follows the pattern: `<scheme>://<authority><absolute path>?<query>#<fragment>`

Relative URI references (which are always hierarchical) follow one of two patterns: `<relative or absolute path>?<query>#<fragment>` or `//<authority><absolute path>?<query>#<fragment>`

An opaque URI follows this pattern: `<scheme>:<opaque part>#<fragment>`

Use `https://developer.android.com/reference/kotlin/android/net/Uri#buildUpon()` to obtain a builder representing an existing URI.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#Builder()()` Constructs a new Builder. |

| Public methods ||
|---|---|
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#appendEncodedPath(kotlin.String)(newSegment: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Appends the given segment to the path. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#appendPath(kotlin.String)(newSegment: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Encodes the given segment and appends it to the path. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#appendQueryParameter(kotlin.String,%20kotlin.String)(key: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!, value: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Encodes the key and value and then appends the parameter to the query string. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#authority(kotlin.String)(authority: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Encodes and sets the authority. |
| [Uri](https://developer.android.com/reference/kotlin/android/net/Uri)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#build()()` Constructs a Uri with the current attributes. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#clearQuery()()` Clears the the previously set query. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#encodedAuthority(kotlin.String)(authority: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the previously encoded authority. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#encodedFragment(kotlin.String)(fragment: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the previously encoded fragment. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#encodedOpaquePart(kotlin.String)(opaquePart: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the previously encoded opaque scheme-specific-part. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#encodedPath(kotlin.String)(path: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the previously encoded path. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#encodedQuery(kotlin.String)(query: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the previously encoded query. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#fragment(kotlin.String)(fragment: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Encodes and sets the fragment. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#opaquePart(kotlin.String)(opaquePart: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Encodes and sets the given opaque scheme-specific-part. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#path(kotlin.String)(path: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the path. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#query(kotlin.String)(query: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Encodes and sets the query. |
| [Uri.Builder](https://developer.android.com/reference/kotlin/android/net/Uri.Builder#)! | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#scheme(kotlin.String)(scheme: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the scheme. |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | `https://developer.android.com/reference/kotlin/android/net/Uri.Builder#toString()()` Returns a string representation of the object. |

## Public constructors

### Builder

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

```
Builder()
```

Constructs a new Builder.

## Public methods

### appendEncodedPath

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

```
fun appendEncodedPath(newSegment: String!): Uri.Builder!
```

Appends the given segment to the path.

### appendPath

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

```
fun appendPath(newSegment: String!): Uri.Builder!
```

Encodes the given segment and appends it to the path.

### appendQueryParameter

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

```
fun appendQueryParameter(
    key: String!, 
    value: String!
): Uri.Builder!
```

Encodes the key and value and then appends the parameter to the query string.

| Parameters ||
|---|---|
| `key` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: which will be encoded |
| `value` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: which will be encoded |

### authority

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

```
fun authority(authority: String!): Uri.Builder!
```

Encodes and sets the authority.

### build

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

```
fun build(): Uri!
```

Constructs a Uri with the current attributes.

| Exceptions ||
|---|---|
| `java.lang.UnsupportedOperationException` | if the URI is opaque and the scheme is null |

### clearQuery

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

```
fun clearQuery(): Uri.Builder!
```

Clears the the previously set query.

### encodedAuthority

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

```
fun encodedAuthority(authority: String!): Uri.Builder!
```

Sets the previously encoded authority.

### encodedFragment

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

```
fun encodedFragment(fragment: String!): Uri.Builder!
```

Sets the previously encoded fragment.

### encodedOpaquePart

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

```
fun encodedOpaquePart(opaquePart: String!): Uri.Builder!
```

Sets the previously encoded opaque scheme-specific-part.

| Parameters ||
|---|---|
| `opaquePart` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: encoded opaque part |

### encodedPath

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

```
fun encodedPath(path: String!): Uri.Builder!
```

Sets the previously encoded path.

If the path is not null and doesn't start with a '/', and if you specify a scheme and/or authority, the builder will prepend the given path with a '/'.

### encodedQuery

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

```
fun encodedQuery(query: String!): Uri.Builder!
```

Sets the previously encoded query.

### fragment

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

```
fun fragment(fragment: String!): Uri.Builder!
```

Encodes and sets the fragment.

### opaquePart

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

```
fun opaquePart(opaquePart: String!): Uri.Builder!
```

Encodes and sets the given opaque scheme-specific-part.

| Parameters ||
|---|---|
| `opaquePart` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: decoded opaque part |

### path

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

```
fun path(path: String!): Uri.Builder!
```

Sets the path. Leaves '/' characters intact but encodes others as necessary.

If the path is not null and doesn't start with a '/', and if you specify a scheme and/or authority, the builder will prepend the given path with a '/'.

### query

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

```
fun query(query: String!): Uri.Builder!
```

Encodes and sets the query.

### scheme

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

```
fun scheme(scheme: String!): Uri.Builder!
```

Sets the scheme.

| Parameters ||
|---|---|
| `scheme` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: name or `null` if this is a relative Uri |

### toString

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

```
fun toString(): String
```

Returns a string representation of the object.

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | a string representation of the object. |