# Uri.Builder

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/net/Uri.Builder#pubctors)\|[Methods](https://developer.android.com/reference/android/net/Uri.Builder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/net/Uri.Builder#inhmethods)  

# Uri.Builder

*** ** * ** ***

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

`
public
static
final

class
Uri.Builder
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.Uri.Builder |

<br />

*** ** * ** ***

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[Uri.buildUpon()](https://developer.android.com/reference/android/net/Uri#buildUpon())to obtain a builder representing an existing URI.

## Summary

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

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

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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*.                                                                                             | ||

## Public constructors

### Builder

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

```
public Builder ()
```

Constructs a new Builder.

<br />

## Public methods

### appendEncodedPath

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

```
public Uri.Builder appendEncodedPath (String newSegment)
```

Appends the given segment to the path.

<br />

|          Parameters           ||
|--------------|-----------------|
| `newSegment` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### appendPath

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

```
public Uri.Builder appendPath (String newSegment)
```

Encodes the given segment and appends it to the path.

<br />

|          Parameters           ||
|--------------|-----------------|
| `newSegment` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### appendQueryParameter

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

```
public Uri.Builder appendQueryParameter (String key, 
                String value)
```

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

<br />

|                   Parameters                    ||
|---------|----------------------------------------|
| `key`   | `String`: which will be encoded <br /> |
| `value` | `String`: which will be encoded <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### authority

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

```
public Uri.Builder authority (String authority)
```

Encodes and sets the authority.

<br />

|          Parameters          ||
|-------------|-----------------|
| `authority` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### build

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

```
public Uri build ()
```

Constructs a Uri with the current attributes.

<br />

|                                Returns                                 ||
|----------------------------------------------------------------|--------|
| [Uri](https://developer.android.com/reference/android/net/Uri) | <br /> |

|                                                                            Throws                                                                             ||
|------------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [UnsupportedOperationException](https://developer.android.com/reference/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#ApiLevels)  

```
public Uri.Builder clearQuery ()
```

Clears the the previously set query.

<br />

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### encodedAuthority

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

```
public Uri.Builder encodedAuthority (String authority)
```

Sets the previously encoded authority.

<br />

|          Parameters          ||
|-------------|-----------------|
| `authority` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### encodedFragment

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

```
public Uri.Builder encodedFragment (String fragment)
```

Sets the previously encoded fragment.

<br />

|         Parameters          ||
|------------|-----------------|
| `fragment` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### encodedOpaquePart

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

```
public Uri.Builder encodedOpaquePart (String opaquePart)
```

Sets the previously encoded opaque scheme-specific-part.

<br />

|                     Parameters                     ||
|--------------|--------------------------------------|
| `opaquePart` | `String`: encoded opaque part <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### encodedPath

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

```
public Uri.Builder encodedPath (String path)
```

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 '/'.

<br />

|       Parameters        ||
|--------|-----------------|
| `path` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### encodedQuery

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

```
public Uri.Builder encodedQuery (String query)
```

Sets the previously encoded query.

<br />

|        Parameters        ||
|---------|-----------------|
| `query` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### fragment

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

```
public Uri.Builder fragment (String fragment)
```

Encodes and sets the fragment.

<br />

|         Parameters          ||
|------------|-----------------|
| `fragment` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### opaquePart

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

```
public Uri.Builder opaquePart (String opaquePart)
```

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

<br />

|                     Parameters                     ||
|--------------|--------------------------------------|
| `opaquePart` | `String`: decoded opaque part <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### path

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

```
public Uri.Builder path (String path)
```

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 '/'.

<br />

|       Parameters        ||
|--------|-----------------|
| `path` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### query

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

```
public Uri.Builder query (String query)
```

Encodes and sets the query.

<br />

|        Parameters        ||
|---------|-----------------|
| `query` | `String` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### scheme

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

```
public Uri.Builder scheme (String scheme)
```

Sets the scheme.

<br />

|                            Parameters                             ||
|----------|---------------------------------------------------------|
| `scheme` | `String`: name or`null`if this is a relative Uri <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Uri.Builder](https://developer.android.com/reference/android/net/Uri.Builder) | <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of the object.

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |