Most visited

Recently visited

Added in API level 1

Uri

public abstract class Uri
extends Object implements Parcelable, Comparable<Uri>

java.lang.Object
    android.net.Uri


不可变的URI引用。 一个URI引用包括一个URI和一个片段,URI后面的一个'#'。 构建和分析符合RFC 2396的 URI引用。

为了提高性能,该课程几乎不进行任何验证。 行为未定义为无效输入。 这个类非常宽容 - 面对无效输入,它将返回垃圾,而不是抛出异常,除非另有说明。

摘要(Summary)

Nested classes

class Uri.Builder

帮助程序类用于构建或操作URI引用。

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<Uri> CREATOR

从Parcels读取Uris。

public static final Uri EMPTY

空的URI,等同于“”。

公共方法(Public methods)

abstract Uri.Builder buildUpon()

构建一个新的构建器,复制这个Uri的属性。

int compareTo(Uri other)

将这个Uri的字符串表示与另一个Uri的字符串表示进行比较。

static String decode(String s)

解码'%' - 使用UTF-8方案在给定字符串中转义的八位字节。

static String encode(String s, String allow)

将给定字符串中的字符编码为'%' - 使用UTF-8方案转义字节。

static String encode(String s)

将给定字符串中的字符编码为'%' - 使用UTF-8方案转义字节。

boolean equals(Object o)

将这个Uri与另一个平等对象进行比较。

static Uri fromFile(File file)

从文件创建一个Uri。

static Uri fromParts(String scheme, String ssp, String fragment)

从给定的组件创建一个不透明的Uri。

abstract String getAuthority()

获取此URI的解码权威部分。

boolean getBooleanQueryParameter(String key, boolean defaultValue)

使用给定键在查询字符串中搜索第一个值,并将其解释为布尔值。

abstract String getEncodedAuthority()

获取此URI的编码权威部分。

abstract String getEncodedFragment()

获取此URI的编码片段部分,即'#'后面的所有内容。

abstract String getEncodedPath()

获取编码路径。

abstract String getEncodedQuery()

从此URI获取编码的查询组件。

abstract String getEncodedSchemeSpecificPart()

获取该URI的方案特定部分,即方案分隔符':'和片段分隔符'#'之间的所有内容。

abstract String getEncodedUserInfo()

从机构获取已编码的用户信息。

abstract String getFragment()

获取此URI的解码片段部分,即'#'后面的所有内容。

abstract String getHost()

从此URI的权限获取编码主机。

abstract String getLastPathSegment()

获取路径中已解码的最后一段。

abstract String getPath()

获取解码的路径。

abstract List<String> getPathSegments()

获取解码的路径段。

abstract int getPort()

从此URI的权限获取端口。

abstract String getQuery()

从此URI获取已解码的查询组件。

String getQueryParameter(String key)

用给定的键搜索查询字符串中的第一个值。

Set<String> getQueryParameterNames()

返回一组所有查询参数的唯一名称。

List<String> getQueryParameters(String key)

使用给定的键在查询字符串中搜索参数值。

abstract String getScheme()

获取此URI的方案。

abstract String getSchemeSpecificPart()

获取该URI的方案特定部分,即方案分隔符':'和片段分隔符'#'之间的所有内容。

abstract String getUserInfo()

从机构获取解码后的用户信息。

int hashCode()

将此Uri的编码字符串表示与 equals(Object)一致。

boolean isAbsolute()

如果这个URI是绝对的,也就是说它包含一个明确的方案,则返回true。

abstract boolean isHierarchical()

如果此URI的层次结构类似“http://google.com”,则返回true。

boolean isOpaque()

如果此URI不透明,如“mailto:[email protected]”,则返回true。

abstract boolean isRelative()

如果此URI是相对的,则返回true,即,如果它不包含显式方案。

Uri normalizeScheme()

用小写的方案组件返回一个等效的URI。

static Uri parse(String uriString)

创建一个分析给定编码的URI字符串的Uri。

abstract String toString()

返回此URI的编码字符串表示形式。

static Uri withAppendedPath(Uri baseUri, String pathSegment)

通过将已编码的路径段附加到基本Uri来创建新的Uri。

static void writeToParcel(Parcel out, Uri uri)

写一个Uri到一个包裹。

继承方法(Inherited methods)

From class java.lang.Object
From interface android.os.Parcelable
From interface java.lang.Comparable

Fields

CREATOR

Added in API level 1
Creator<Uri> CREATOR

从Parcels读取Uris。

EMPTY

Added in API level 1
Uri EMPTY

空的URI,等同于“”。

公共方法(Public methods)

buildUpon

Added in API level 1
Uri.Builder buildUpon ()

构建一个新的构建器,复制这个Uri的属性。

返回(Returns)
Uri.Builder

compareTo

Added in API level 1
int compareTo (Uri other)

将这个Uri的字符串表示与另一个Uri的字符串表示进行比较。

参数(Parameters)
other Uri
返回(Returns)
int

decode

Added in API level 1
String decode (String s)

解码'%' - 使用UTF-8方案在给定字符串中转义的八位字节。 用unicode替换字符(“\\ uFFFD”)替换无效的八位字节。

参数(Parameters)
s String: encoded string to decode
返回(Returns)
String the given string with escaped octets decoded, or null if s is null

encode

Added in API level 1
String encode (String s, 
                String allow)

将给定字符串中的字符编码为'%' - 使用UTF-8方案转义字节。 留下字母(“AZ”,“az”),数字(“0-9”)和未保留字符(“_- !.'()*”)完好无损。 编码除allow参数中指定的字符外的所有其他字符。

参数(Parameters)
s String: string to encode
allow String: set of additional characters to allow in the encoded form, null if no characters should be skipped
返回(Returns)
String an encoded version of s suitable for use as a URI component, or null if s is null

encode

Added in API level 1
String encode (String s)

将给定字符串中的字符编码为'%' - 使用UTF-8方案转义字节。 留下字母(“AZ”,“az”),数字(“0-9”)和未保留字符(“_- !.'()*”)完好无损。 编码所有其他字符。

参数(Parameters)
s String: string to encode
返回(Returns)
String an encoded version of s suitable for use as a URI component, or null if s is null

equals

Added in API level 1
boolean equals (Object o)

将这个Uri与另一个平等对象进行比较。 如果此Uri的编码字符串表示和给定的Uri相等,则返回true。 案件数量。 路径没有正常化。 如果一个Uri明确指定了默认端口,而另一个则隐含默认端口,则它们不会被视为相等。

参数(Parameters)
o Object: the reference object with which to compare.
返回(Returns)
boolean true if this object is the same as the obj argument; false otherwise.

fromFile

Added in API level 1
Uri fromFile (File file)

从文件创建一个Uri。 该URI的格式为“file:// “。编码除'/'外的路径字符。

例如:“file:///tmp/android.txt”

参数(Parameters)
file File
返回(Returns)
Uri a Uri for the given file
抛出异常(Throws)
NullPointerException if file is null

fromParts

Added in API level 1
Uri fromParts (String scheme, 
                String ssp, 
                String fragment)

从给定的组件创建一个不透明的Uri。 对ssp进行编码,这意味着此方法不能用于创建分层URI。

参数(Parameters)
scheme String: of the URI
ssp String: scheme-specific-part, everything between the scheme separator (':') and the fragment separator ('#'), which will get encoded
fragment String: fragment, everything after the '#', null if undefined, will get encoded
返回(Returns)
Uri Uri composed of the given scheme, ssp, and fragment
抛出异常(Throws)
NullPointerException if scheme or ssp is null

也可以看看:

getAuthority

Added in API level 1
String getAuthority ()

获取此URI的解码权威部分。 对于服务器地址,权限的结构如下: [ userinfo '@' ] host [ ':' port ]

示例:“google.com”,“[email protected]:80”

返回(Returns)
String the authority for this URI or null if not present

getBooleanQueryParameter

Added in API level 11
boolean getBooleanQueryParameter (String key, 
                boolean defaultValue)

使用给定键在查询字符串中搜索第一个值,并将其解释为布尔值。 “假”和“0”被解释为false ,其他所有解释为true

参数(Parameters)
key String: which will be decoded
defaultValue boolean: the default value to return if there is no query parameter for key
返回(Returns)
boolean the boolean interpretation of the query parameter key

getEncodedAuthority

Added in API level 1
String getEncodedAuthority ()

获取此URI的编码权威部分。 对于服务器地址,权限的结构如下: [ userinfo '@' ] host [ ':' port ]

示例:“google.com”,“[email protected]:80”

返回(Returns)
String the authority for this URI or null if not present

getEncodedFragment

Added in API level 1
String getEncodedFragment ()

获取此URI的编码片段部分,即'#'后面的所有内容。

返回(Returns)
String the encoded fragment or null if there isn't one

getEncodedPath

Added in API level 1
String getEncodedPath ()

获取编码路径。

返回(Returns)
String the encoded path, or null if this is not a hierarchical URI (like "mailto:[email protected]") or the URI is invalid

getEncodedQuery

Added in API level 1
String getEncodedQuery ()

从此URI获取编码的查询组件。 查询出现在查询分隔符('?')之后和碎片分隔符('#')之前。 此方法将为“http://www.google.com/search?q=android”返回“q = android”。

返回(Returns)
String the encoded query or null if there isn't one

getEncodedSchemeSpecificPart

Added in API level 1
String getEncodedSchemeSpecificPart ()

获取该URI的方案特定部分,即方案分隔符':'和片段分隔符'#'之间的所有内容。 如果这是一个相对URI,则此方法返回整个URI。 叶子完整地逃脱了八位组。

例如:“//www.google.com/search?q=android”

返回(Returns)
String the decoded scheme-specific-part

getEncodedUserInfo

Added in API level 1
String getEncodedUserInfo ()

从机构获取已编码的用户信息。 例如,如果权限是“[email protected]”,则此方法将返回“nobody”。

返回(Returns)
String the user info for this URI or null if not present

getFragment

Added in API level 1
String getFragment ()

获取此URI的解码片段部分,即'#'后面的所有内容。

返回(Returns)
String the decoded fragment or null if there isn't one

getHost

Added in API level 1
String getHost ()

从此URI的权限获取编码主机。 例如,如果权威是“[email protected]”,则此方法将返回“google.com”。

返回(Returns)
String the host for this URI or null if not present

getLastPathSegment

Added in API level 1
String getLastPathSegment ()

获取路径中已解码的最后一段。

返回(Returns)
String the decoded last segment or null if the path is empty

getPath

Added in API level 1
String getPath ()

获取解码的路径。

返回(Returns)
String the decoded path, or null if this is not a hierarchical URI (like "mailto:[email protected]") or the URI is invalid

getPathSegments

Added in API level 1
List<String> getPathSegments ()

获取解码的路径段。

返回(Returns)
List<String> decoded path segments, each without a leading or trailing '/'

getPort

Added in API level 1
int getPort ()

从此URI的权限获取端口。 例如,如果权威是“google.com:80”,则此方法将返回80。

返回(Returns)
int the port for this URI or -1 if invalid or not present

getQuery

Added in API level 1
String getQuery ()

从此URI获取已解码的查询组件。 查询出现在查询分隔符('?')之后和碎片分隔符('#')之前。 此方法将为“http://www.google.com/search?q=android”返回“q = android”。

返回(Returns)
String the decoded query or null if there isn't one

getQueryParameter

Added in API level 1
String getQueryParameter (String key)

用给定的键搜索查询字符串中的第一个值。

警告:在Jelly Bean之前,将'+'字符解码为'+'而不是''。

参数(Parameters)
key String: which will be encoded
返回(Returns)
String the decoded value or null if no parameter is found
抛出异常(Throws)
UnsupportedOperationException if this isn't a hierarchical URI
NullPointerException if key is null

getQueryParameterNames

Added in API level 11
Set<String> getQueryParameterNames ()

返回一组所有查询参数的唯一名称。 遍历集合将按照它们的第一次出现的顺序返回名称。

返回(Returns)
Set<String> a set of decoded names
抛出异常(Throws)
UnsupportedOperationException if this isn't a hierarchical URI

getQueryParameters

Added in API level 1
List<String> getQueryParameters (String key)

使用给定的键在查询字符串中搜索参数值。

参数(Parameters)
key String: which will be encoded
返回(Returns)
List<String> a list of decoded values
抛出异常(Throws)
UnsupportedOperationException if this isn't a hierarchical URI
NullPointerException if key is null

getScheme

Added in API level 1
String getScheme ()

获取此URI的方案。 例如:“http”

返回(Returns)
String the scheme or null if this is a relative URI

getSchemeSpecificPart

Added in API level 1
String getSchemeSpecificPart ()

获取该URI的方案特定部分,即方案分隔符':'和片段分隔符'#'之间的所有内容。 如果这是一个相对URI,则此方法返回整个URI。 解码转义的八位字节。

例如:“//www.google.com/search?q=android”

返回(Returns)
String the decoded scheme-specific-part

getUserInfo

Added in API level 1
String getUserInfo ()

从机构获取解码后的用户信息。 例如,如果权限是“[email protected]”,则此方法将返回“nobody”。

返回(Returns)
String the user info for this URI or null if not present

hashCode

Added in API level 1
int hashCode ()

将此Uri的编码字符串表示与 equals(Object)一致。

返回(Returns)
int a hash code value for this object.

isAbsolute

Added in API level 1
boolean isAbsolute ()

如果这个URI是绝对的,也就是说它包含一个明确的方案,则返回true。

返回(Returns)
boolean true if this URI is absolute, false if it's relative

isHierarchical

Added in API level 1
boolean isHierarchical ()

如果此URI的层次结构类似“http://google.com”,则返回true。 如果特定于方案的部分以'/'开始,则绝对URI是分层的。 相对URI始终是分层的。

返回(Returns)
boolean

isOpaque

Added in API level 1
boolean isOpaque ()

如果此URI不透明,如“mailto:[email protected]”,则返回true。 不透明URI的方案特定部分不能以'/'开头。

返回(Returns)
boolean

isRelative

Added in API level 1
boolean isRelative ()

如果此URI是相对的,则返回true,即,如果它不包含显式方案。

返回(Returns)
boolean true if this URI is relative, false if it's absolute

normalizeScheme

Added in API level 16
Uri normalizeScheme ()

用小写的方案组件返回一个等效的URI。 这将Uri与Android最佳实践进行意向过滤对齐。

例如,“HTTP://www.android.com”变成“http://www.android.com”

从外部Android接收到的所有URI(例如用户输入或外部来源,如蓝牙,NFC或互联网)应在用于创建Intent之前进行规范化。

此方法验证错误的URI的,或“修复”格式混乱的URI的-所以不要用它来输入验证。 Uri将始终返回,即使Uri的格式不正确并且无法找到计划组件。

返回(Returns)
Uri normalized Uri (never null)

也可以看看:

parse

Added in API level 1
Uri parse (String uriString)

创建一个分析给定编码的URI字符串的Uri。

参数(Parameters)
uriString String: an RFC 2396-compliant, encoded URI
返回(Returns)
Uri Uri for this given uri string
抛出异常(Throws)
NullPointerException if uriString is null

toString

Added in API level 1
String toString ()

返回此URI的编码字符串表示形式。 例如:“http://google.com/”

返回(Returns)
String a string representation of the object.

withAppendedPath

Added in API level 1
Uri withAppendedPath (Uri baseUri, 
                String pathSegment)

通过将已编码的路径段附加到基本Uri来创建新的Uri。

参数(Parameters)
baseUri Uri: Uri to append path segment to
pathSegment String: encoded path segment to append
返回(Returns)
Uri a new Uri based on baseUri with the given segment appended to the path
抛出异常(Throws)
NullPointerException if baseUri is null

writeToParcel

Added in API level 1
void writeToParcel (Parcel out, 
                Uri uri)

写一个Uri到一个包裹。

参数(Parameters)
out Parcel: parcel to write to
uri Uri: to write, can be null

Hooray!