java.lang.Object | |
↳ | android.net.Uri |
Immutable URI reference. A URI reference includes a URI and a fragment, the component of the URI following a '#'. Builds and parses URI references which conform to RFC 2396 .
In the interest of performance, this class performs little to no validation. Behavior is undefined for invalid input. This class is very forgiving--in the face of invalid input, it will return garbage rather than throw an exception unless otherwise specified.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Uri.Builder | Helper class for building or manipulating URI references. |
[Expand]
Inherited Constants
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
CREATOR | Reads Uris from Parcels. | |||||||||
|
EMPTY | The empty URI, equivalent to "". |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Constructs a new builder, copying the attributes from this Uri.
|
||||||||||
|
Compares the string representation of this Uri with that of
another.
|
||||||||||
|
Decodes '%'-escaped octets in the given string using the UTF-8 scheme.
|
||||||||||
|
Encodes characters in the given string as '%'-escaped octets
using the UTF-8 scheme.
|
||||||||||
|
Encodes characters in the given string as '%'-escaped octets
using the UTF-8 scheme.
|
||||||||||
|
Compares this Uri to another object for equality.
|
||||||||||
|
Creates a Uri from a file.
|
||||||||||
|
Creates an opaque Uri from the given components.
|
||||||||||
|
Gets the decoded authority part of this URI.
|
||||||||||
|
Searches the query string for the first value with the given key and interprets it
as a boolean value.
|
||||||||||
|
Gets the encoded authority part of this URI.
|
||||||||||
|
Gets the encoded fragment part of this URI, everything after the '#'.
|
||||||||||
|
Gets the encoded path.
|
||||||||||
|
Gets the encoded query component from this URI.
|
||||||||||
|
Gets the scheme-specific part of this URI, i.e.
|
||||||||||
|
Gets the encoded user information from the authority.
|
||||||||||
|
Gets the decoded fragment part of this URI, everything after the '#'.
|
||||||||||
|
Gets the encoded host from the authority for this URI.
|
||||||||||
|
Gets the decoded last segment in the path.
|
||||||||||
|
Gets the decoded path.
|
||||||||||
|
Gets the decoded path segments.
|
||||||||||
|
Gets the port from the authority for this URI.
|
||||||||||
|
Gets the decoded query component from this URI.
|
||||||||||
|
Searches the query string for the first value with the given key.
|
||||||||||
|
Returns a set of the unique names of all query parameters.
|
||||||||||
|
Searches the query string for parameter values with the given key.
|
||||||||||
|
Gets the scheme of this URI.
|
||||||||||
|
Gets the scheme-specific part of this URI, i.e.
|
||||||||||
|
Gets the decoded user information from the authority.
|
||||||||||
|
Hashes the encoded string represention of this Uri consistently with
equals(Object)
.
|
||||||||||
|
Returns true if this URI is absolute, i.e.
|
||||||||||
|
Returns true if this URI is hierarchical like "http://google.com".
|
||||||||||
|
Returns true if this URI is opaque like "mailto:[email protected]".
|
||||||||||
|
Returns true if this URI is relative, i.e.
|
||||||||||
|
Return an equivalent URI with a lowercase scheme component.
|
||||||||||
|
Creates a Uri which parses the given encoded URI string.
|
||||||||||
|
Returns the encoded string representation of this URI.
|
||||||||||
|
Creates a new Uri by appending an already-encoded path segment to a
base Uri.
|
||||||||||
|
Writes a Uri to a Parcel.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
|||||||||||
From interface
android.os.Parcelable
|
|||||||||||
From interface
java.lang.Comparable
|
Constructs a new builder, copying the attributes from this Uri.
Compares the string representation of this Uri with that of another.
Decodes '%'-escaped octets in the given string using the UTF-8 scheme. Replaces invalid octets with the unicode replacement character ("\\uFFFD").
s | encoded string to decode |
---|
Encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme. Leaves letters ("A-Z", "a-z"), numbers ("0-9"), and unreserved characters ("_-!.~'()*") intact. Encodes all other characters with the exception of those specified in the allow argument.
s | string to encode |
---|---|
allow | set of additional characters to allow in the encoded form, null if no characters should be skipped |
Encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme. Leaves letters ("A-Z", "a-z"), numbers ("0-9"), and unreserved characters ("_-!.~'()*") intact. Encodes all other characters.
s | string to encode |
---|
Compares this Uri to another object for equality. Returns true if the encoded string representations of this Uri and the given Uri are equal. Case counts. Paths are not normalized. If one Uri specifies a default port explicitly and the other leaves it implicit, they will not be considered equal.
o | the object to compare this instance with. |
---|
true
if the specified object is equal to this
Object
;
false
otherwise.
Creates a Uri from a file. The URI has the form
"file://
Example: "file:///tmp/android.txt"
NullPointerException | if file is null |
---|
Creates an opaque Uri from the given components. Encodes the ssp which means this method cannot be used to create hierarchical URIs.
scheme | of the URI |
---|---|
ssp | scheme-specific-part, everything between the scheme separator (':') and the fragment separator ('#'), which will get encoded |
fragment | fragment, everything after the '#', null if undefined, will get encoded |
NullPointerException | if scheme or ssp is null |
---|
Gets the decoded authority part of this URI. For
server addresses, the authority is structured as follows:
[ userinfo '@' ] host [ ':' port ]
Examples: "google.com", "[email protected]:80"
Searches the query string for the first value with the given key and interprets it
as a boolean value. "false" and "0" are interpreted as
false
, everything
else is interpreted as
true
.
key | which will be decoded |
---|---|
defaultValue | the default value to return if there is no query parameter for key |
Gets the encoded authority part of this URI. For
server addresses, the authority is structured as follows:
[ userinfo '@' ] host [ ':' port ]
Examples: "google.com", "[email protected]:80"
Gets the encoded fragment part of this URI, everything after the '#'.
Gets the encoded path.
Gets the encoded query component from this URI. The query comes after the query separator ('?') and before the fragment separator ('#'). This method would return "q=android" for "http://www.google.com/search?q=android".
Gets the scheme-specific part of this URI, i.e. everything between the scheme separator ':' and the fragment separator '#'. If this is a relative URI, this method returns the entire URI. Leaves escaped octets intact.
Example: "//www.google.com/search?q=android"
Gets the encoded user information from the authority. For example, if the authority is "[email protected]", this method will return "nobody".
Gets the decoded fragment part of this URI, everything after the '#'.
Gets the encoded host from the authority for this URI. For example, if the authority is "[email protected]", this method will return "google.com".
Gets the decoded last segment in the path.
Gets the decoded path.
Gets the decoded path segments.
Gets the port from the authority for this URI. For example, if the authority is "google.com:80", this method will return 80.
Gets the decoded query component from this URI. The query comes after the query separator ('?') and before the fragment separator ('#'). This method would return "q=android" for "http://www.google.com/search?q=android".
Searches the query string for the first value with the given key.
Warning: Prior to Ice Cream Sandwich, this decoded the '+' character as '+' rather than ' '.
key | which will be encoded |
---|
UnsupportedOperationException | if this isn't a hierarchical URI |
---|---|
NullPointerException | if key is null |
Returns a set of the unique names of all query parameters. Iterating over the set will return the names in order of their first occurrence.
UnsupportedOperationException | if this isn't a hierarchical URI |
---|
Searches the query string for parameter values with the given key.
key | which will be encoded |
---|
UnsupportedOperationException | if this isn't a hierarchical URI |
---|---|
NullPointerException | if key is null |
Gets the scheme of this URI. Example: "http"
Gets the scheme-specific part of this URI, i.e. everything between the scheme separator ':' and the fragment separator '#'. If this is a relative URI, this method returns the entire URI. Decodes escaped octets.
Example: "//www.google.com/search?q=android"
Gets the decoded user information from the authority. For example, if the authority is "[email protected]", this method will return "nobody".
Hashes the encoded string represention of this Uri consistently with
equals(Object)
.
Returns true if this URI is absolute, i.e. if it contains an explicit scheme.
Returns true if this URI is hierarchical like "http://google.com". Absolute URIs are hierarchical if the scheme-specific part starts with a '/'. Relative URIs are always hierarchical.
Returns true if this URI is opaque like "mailto:[email protected]". The scheme-specific part of an opaque URI cannot start with a '/'.
Returns true if this URI is relative, i.e. if it doesn't contain an explicit scheme.
Return an equivalent URI with a lowercase scheme component. This aligns the Uri with Android best practices for intent filtering.
For example, "HTTP://www.android.com" becomes "http://www.android.com"
All URIs received from outside Android (such as user input, or external sources like Bluetooth, NFC, or the Internet) should be normalized before they are used to create an Intent.
This method does not validate bad URI's, or 'fix' poorly formatted URI's - so do not use it for input validation. A Uri will always be returned, even if the Uri is badly formatted to begin with and a scheme component cannot be found.
Creates a Uri which parses the given encoded URI string.
uriString | an RFC 2396-compliant, encoded URI |
---|
NullPointerException | if uriString is null |
---|
Returns the encoded string representation of this URI. Example: "http://google.com/"
Creates a new Uri by appending an already-encoded path segment to a base Uri.
baseUri | Uri to append path segment to |
---|---|
pathSegment | encoded path segment to append |
NullPointerException | if baseUri is null |
---|
Writes a Uri to a Parcel.
out | parcel to write to |
---|---|
uri | to write, can be null |