public abstract class Uri extends Object implements Parcelable, Comparable<Uri>
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.
Modifier and Type | Class and Description |
---|---|
static class |
Uri.Builder
Helper class for building or manipulating URI references.
|
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<Uri> |
CREATOR
Reads Uris from Parcels.
|
static Uri |
EMPTY
The empty URI, equivalent to "".
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
abstract Uri.Builder |
buildUpon()
Constructs a new builder, copying the attributes from this Uri.
|
int |
compareTo(Uri other)
Compares the string representation of this Uri with that of
another.
|
static String |
decode(String s)
Decodes '%'-escaped octets in the given string using the UTF-8 scheme.
|
static String |
encode(String s)
Encodes characters in the given string as '%'-escaped octets
using the UTF-8 scheme.
|
static String |
encode(String s,
String allow)
Encodes characters in the given string as '%'-escaped octets
using the UTF-8 scheme.
|
boolean |
equals(Object o)
Compares this Uri to another object for equality.
|
static Uri |
fromFile(File file)
Creates a Uri from a file.
|
static Uri |
fromParts(String scheme,
String ssp,
String fragment)
Creates an opaque Uri from the given components.
|
abstract String |
getAuthority()
Gets the decoded authority part of this URI.
|
boolean |
getBooleanQueryParameter(String key,
boolean defaultValue)
Searches the query string for the first value with the given key and interprets it
as a boolean value.
|
Uri |
getCanonicalUri()
If this
Uri is file:// , then resolve and return its
canonical path. |
abstract String |
getEncodedAuthority()
Gets the encoded authority part of this URI.
|
abstract String |
getEncodedFragment()
Gets the encoded fragment part of this URI, everything after the '#'.
|
abstract String |
getEncodedPath()
Gets the encoded path.
|
abstract String |
getEncodedQuery()
Gets the encoded query component from this URI.
|
abstract String |
getEncodedSchemeSpecificPart()
Gets the scheme-specific part of this URI, i.e.
|
abstract String |
getEncodedUserInfo()
Gets the encoded user information from the authority.
|
abstract String |
getFragment()
Gets the decoded fragment part of this URI, everything after the '#'.
|
abstract String |
getHost()
Gets the encoded host from the authority for this URI.
|
abstract String |
getLastPathSegment()
Gets the decoded last segment in the path.
|
abstract String |
getPath()
Gets the decoded path.
|
abstract List<String> |
getPathSegments()
Gets the decoded path segments.
|
abstract int |
getPort()
Gets the port from the authority for this URI.
|
abstract String |
getQuery()
Gets the decoded query component from this URI.
|
String |
getQueryParameter(String key)
Searches the query string for the first value with the given key.
|
Set<String> |
getQueryParameterNames()
Returns a set of the unique names of all query parameters.
|
List<String> |
getQueryParameters(String key)
Searches the query string for parameter values with the given key.
|
abstract String |
getScheme()
Gets the scheme of this URI.
|
abstract String |
getSchemeSpecificPart()
Gets the scheme-specific part of this URI, i.e.
|
abstract String |
getUserInfo()
Gets the decoded user information from the authority.
|
int |
hashCode()
Hashes the encoded string represention of this Uri consistently with
equals(Object) . |
boolean |
isAbsolute()
Returns true if this URI is absolute, i.e.
|
abstract boolean |
isHierarchical()
Returns true if this URI is hierarchical like "http://google.com".
|
boolean |
isOpaque()
Returns true if this URI is opaque like "mailto:nobody@google.com".
|
abstract boolean |
isRelative()
Returns true if this URI is relative, i.e.
|
Uri |
normalizeScheme()
Return an equivalent URI with a lowercase scheme component.
|
static Uri |
parse(String uriString)
Creates a Uri which parses the given encoded URI string.
|
String |
toSafeString()
Return a string representation of the URI that is safe to print
to logs and other places where PII should be avoided.
|
abstract String |
toString()
Returns the encoded string representation of this URI.
|
static Uri |
withAppendedPath(Uri baseUri,
String pathSegment)
Creates a new Uri by appending an already-encoded path segment to a
base Uri.
|
static void |
writeToParcel(Parcel out,
Uri uri)
Writes a Uri to a Parcel.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
describeContents, writeToParcel
public static final Uri EMPTY
public static final Parcelable.Creator<Uri> CREATOR
public abstract boolean isHierarchical()
public boolean isOpaque()
public abstract boolean isRelative()
public boolean isAbsolute()
public abstract String getScheme()
public abstract String getSchemeSpecificPart()
Example: "//www.google.com/search?q=android"
public abstract String getEncodedSchemeSpecificPart()
Example: "//www.google.com/search?q=android"
public abstract String getAuthority()
[ userinfo '@' ] host [ ':' port ]
Examples: "google.com", "bob@google.com:80"
public abstract String getEncodedAuthority()
[ userinfo '@' ] host [ ':' port ]
Examples: "google.com", "bob@google.com:80"
public abstract String getUserInfo()
public abstract String getEncodedUserInfo()
public abstract String getHost()
public abstract int getPort()
public abstract String getPath()
public abstract String getEncodedPath()
public abstract String getQuery()
public abstract String getEncodedQuery()
public abstract String getFragment()
public abstract String getEncodedFragment()
public abstract List<String> getPathSegments()
public abstract String getLastPathSegment()
public boolean equals(Object o)
equals
in class Object
o
- the object to compare this instance with.true
if the specified object is equal to this Object
; false
otherwise.Object.hashCode()
public int hashCode()
equals(Object)
.hashCode
in class Object
Object.equals(java.lang.Object)
public int compareTo(Uri other)
compareTo
in interface Comparable<Uri>
other
- the object to compare to this instance.another
;
a positive integer if this instance is greater than
another
; 0 if this instance has the same order as
another
.public abstract String toString()
public String toSafeString()
public abstract Uri.Builder buildUpon()
public static Uri parse(String uriString)
uriString
- an RFC 2396-compliant, encoded URINullPointerException
- if uriString is nullpublic static Uri fromFile(File file)
Example: "file:///tmp/android.txt"
NullPointerException
- if file is nullpublic static Uri fromParts(String scheme, String ssp, String fragment)
scheme
- of the URIssp
- scheme-specific-part, everything between the
scheme separator (':') and the fragment separator ('#'), which will
get encodedfragment
- fragment, everything after the '#', null if undefined,
will get encodedNullPointerException
- if scheme or ssp is nullif you don't want the ssp and fragment to be encoded
public Set<String> getQueryParameterNames()
UnsupportedOperationException
- if this isn't a hierarchical URIpublic List<String> getQueryParameters(String key)
key
- which will be encodedUnsupportedOperationException
- if this isn't a hierarchical URINullPointerException
- if key is nullpublic String getQueryParameter(String key)
Warning: Prior to Ice Cream Sandwich, this decoded the '+' character as '+' rather than ' '.
key
- which will be encodedUnsupportedOperationException
- if this isn't a hierarchical URINullPointerException
- if key is nullpublic boolean getBooleanQueryParameter(String key, boolean defaultValue)
false
, everything
else is interpreted as true
.key
- which will be decodeddefaultValue
- the default value to return if there is no query parameter for keypublic Uri normalizeScheme()
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.
android.content.Intent#setData}
,
#setNormalizedData}
public static void writeToParcel(Parcel out, Uri uri)
out
- parcel to write touri
- to write, can be nullpublic static String encode(String s)
s
- string to encodepublic static String encode(String s, String allow)
s
- string to encodeallow
- set of additional characters to allow in the encoded form,
null if no characters should be skippedpublic static String decode(String s)
s
- encoded string to decodepublic static Uri withAppendedPath(Uri baseUri, String pathSegment)
baseUri
- Uri to append path segment topathSegment
- encoded path segment to appendNullPointerException
- if baseUri is null