Android APIs
public static final class

Uri.Builder

extends Object
java.lang.Object
   ↳ android.net.Uri.Builder

Class Overview

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

An absolute hierarchical URI reference follows the pattern: ://?#

Relative URI references (which are always hierarchical) follow one of two patterns: ?# or //?#

An opaque URI follows this pattern: :#

Use buildUpon() to obtain a builder representing an existing URI.

Summary

Public Constructors
Uri.Builder()
Constructs a new Builder.
Public Methods
Uri.Builder appendEncodedPath(String newSegment)
Appends the given segment to the path.
Uri.Builder appendPath(String newSegment)
Encodes the given segment and appends it to the path.
Uri.Builder appendQueryParameter(String key, String value)
Encodes the key and value and then appends the parameter to the query string.
Uri.Builder authority(String authority)
Encodes and sets the authority.
Uri build()
Constructs a Uri with the current attributes.
Uri.Builder clearQuery()
Clears the the previously set query.
Uri.Builder encodedAuthority(String authority)
Sets the previously encoded authority.
Uri.Builder encodedFragment(String fragment)
Sets the previously encoded fragment.
Uri.Builder encodedOpaquePart(String opaquePart)
Sets the previously encoded opaque scheme-specific-part.
Uri.Builder encodedPath(String path)
Sets the previously encoded path.
Uri.Builder encodedQuery(String query)
Sets the previously encoded query.
Uri.Builder fragment(String fragment)
Encodes and sets the fragment.
Uri.Builder opaquePart(String opaquePart)
Encodes and sets the given opaque scheme-specific-part.
Uri.Builder path(String path)
Sets the path.
Uri.Builder query(String query)
Encodes and sets the query.
Uri.Builder scheme(String scheme)
Sets the scheme.
String toString()
Returns a string containing a concise, human-readable description of this object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Uri.Builder ()

Added in API level 1

Constructs a new Builder.

Public Methods

public Uri.Builder appendEncodedPath (String newSegment)

Added in API level 1

Appends the given segment to the path.

public Uri.Builder appendPath (String newSegment)

Added in API level 1

Encodes the given segment and appends it to the path.

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

Added in API level 1

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

Parameters
key which will be encoded
value which will be encoded

public Uri.Builder authority (String authority)

Added in API level 1

Encodes and sets the authority.

public Uri build ()

Added in API level 1

Constructs a Uri with the current attributes.

Throws
UnsupportedOperationException if the URI is opaque and the scheme is null

public Uri.Builder clearQuery ()

Added in API level 11

Clears the the previously set query.

public Uri.Builder encodedAuthority (String authority)

Added in API level 1

Sets the previously encoded authority.

public Uri.Builder encodedFragment (String fragment)

Added in API level 1

Sets the previously encoded fragment.

public Uri.Builder encodedOpaquePart (String opaquePart)

Added in API level 1

Sets the previously encoded opaque scheme-specific-part.

Parameters
opaquePart encoded opaque part

public Uri.Builder encodedPath (String path)

Added in API level 1

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

public Uri.Builder encodedQuery (String query)

Added in API level 1

Sets the previously encoded query.

public Uri.Builder fragment (String fragment)

Added in API level 1

Encodes and sets the fragment.

public Uri.Builder opaquePart (String opaquePart)

Added in API level 1

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

Parameters
opaquePart decoded opaque part

public Uri.Builder path (String path)

Added in API level 1

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

public Uri.Builder query (String query)

Added in API level 1

Encodes and sets the query.

public Uri.Builder scheme (String scheme)

Added in API level 1

Sets the scheme.

Parameters
scheme name or null if this is a relative Uri

public String toString ()

Added in API level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.