Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Uri.Builder

public static final class Uri.Builder
extends Object

java.lang.Object
   ↳ 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 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 representation of the object.

Inherited methods

From class java.lang.Object

Public constructors

Uri.Builder

Added in API level 1
Uri.Builder ()

Constructs a new Builder.

Public methods

appendEncodedPath

Added in API level 1
Uri.Builder appendEncodedPath (String newSegment)

Appends the given segment to the path.

Parameters
newSegment String
Returns
Uri.Builder

appendPath

Added in API level 1
Uri.Builder appendPath (String newSegment)

Encodes the given segment and appends it to the path.

Parameters
newSegment String
Returns
Uri.Builder

appendQueryParameter

Added in API level 1
Uri.Builder appendQueryParameter (String key, 
                String value)

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

Parameters
key String: which will be encoded
value String: which will be encoded
Returns
Uri.Builder

authority

Added in API level 1
Uri.Builder authority (String authority)

Encodes and sets the authority.

Parameters
authority String
Returns
Uri.Builder

build

Added in API level 1
Uri build ()

Constructs a Uri with the current attributes.

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

clearQuery

Added in API level 11
Uri.Builder clearQuery ()

Clears the the previously set query.

Returns
Uri.Builder

encodedAuthority

Added in API level 1
Uri.Builder encodedAuthority (String authority)

Sets the previously encoded authority.

Parameters
authority String
Returns
Uri.Builder

encodedFragment

Added in API level 1
Uri.Builder encodedFragment (String fragment)

Sets the previously encoded fragment.

Parameters
fragment String
Returns
Uri.Builder

encodedOpaquePart

Added in API level 1
Uri.Builder encodedOpaquePart (String opaquePart)

Sets the previously encoded opaque scheme-specific-part.

Parameters
opaquePart String: encoded opaque part
Returns
Uri.Builder

encodedPath

Added in API level 1
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 '/'.

Parameters
path String
Returns
Uri.Builder

encodedQuery

Added in API level 1
Uri.Builder encodedQuery (String query)

Sets the previously encoded query.

Parameters
query String
Returns
Uri.Builder

fragment

Added in API level 1
Uri.Builder fragment (String fragment)

Encodes and sets the fragment.

Parameters
fragment String
Returns
Uri.Builder

opaquePart

Added in API level 1
Uri.Builder opaquePart (String opaquePart)

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

Parameters
opaquePart String: decoded opaque part
Returns
Uri.Builder

path

Added in API level 1
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 '/'.

Parameters
path String
Returns
Uri.Builder

query

Added in API level 1
Uri.Builder query (String query)

Encodes and sets the query.

Parameters
query String
Returns
Uri.Builder

scheme

Added in API level 1
Uri.Builder scheme (String scheme)

Sets the scheme.

Parameters
scheme String: name or null if this is a relative Uri
Returns
Uri.Builder

toString

Added in API level 1
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

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

Returns
String a string representation of the object.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.