android uri parcel,Uri - Android SDK | Android Developers

本文介绍NestedClasses类,用于从Parcelables创建或解析URI,并提供各种操作方法如比较、编码解码和构建URI。主要关注Uri.Builder的使用和URI的解析规则,包括绝对与相对URI判断、路径操作和查询参数处理。
摘要由CSDN通过智能技术生成

Nested Classes

class

Helper class for building or manipulating URI references.

[Expand]

Inherited Constants

3e54f4822052f69722b015cabe630b87.pngFrom interface

android.os.Parcelable

int

Bit masks for use with

int

Flag for use with Parcelable someFunction()",

"void someFunction(out Parcelable)", or

"void someFunction(inout Parcelable)".

Fields

public

static

final

Creator

Reads Uris from Parcels.

public

static

final

Uri

The empty URI, equivalent to "".

Public Methods

Constructs a new builder, copying the attributes from this Uri.

int

Compares the string representation of this Uri with that of

another.

static

String

Decodes '%'-escaped octets in the given string using the UTF-8 scheme.

static

String

Encodes characters in the given string as '%'-escaped octets

using the UTF-8 scheme.

static

String

Encodes characters in the given string as '%'-escaped octets

using the UTF-8 scheme.

boolean

Compares this Uri to another object for equality.

static

Uri

Creates a Uri from a file.

static

Uri

Creates an opaque Uri from the given components.

abstract

String

Gets the decoded authority part of this URI.

boolean

Searches the query string for the first value with the given key and interprets it

as a boolean value.

abstract

String

Gets the encoded authority part of this URI.

abstract

String

Gets the encoded fragment part of this URI, everything after the '#'.

abstract

String

Gets the encoded path.

abstract

String

Gets the encoded query component from this URI.

abstract

String

Gets the scheme-specific part of this URI, i.e.

abstract

String

Gets the encoded user information from the authority.

abstract

String

Gets the decoded fragment part of this URI, everything after the '#'.

abstract

String

Gets the encoded host from the authority for this URI.

abstract

String

Gets the decoded last segment in the path.

abstract

String

Gets the decoded path.

abstract

List

Gets the decoded path segments.

abstract

int

Gets the port from the authority for this URI.

abstract

String

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.

abstract

String

Gets the scheme of this URI.

abstract

String

Gets the scheme-specific part of this URI, i.e.

abstract

String

Gets the decoded user information from the authority.

int

Hashes the encoded string represention of this Uri consistently with

boolean

Returns true if this URI is absolute, i.e.

abstract

boolean

Returns true if this URI is hierarchical like "http://google.com".

boolean

Returns true if this URI is opaque like "mailto:nobody@google.com".

abstract

boolean

Returns true if this URI is relative, i.e.

Return an equivalent URI with a lowercase scheme component.

static

Uri

String uriString)

Creates a Uri which parses the given encoded URI string.

abstract

String

Returns the encoded string representation of this URI.

static

Uri

Creates a new Uri by appending an already-encoded path segment to a

base Uri.

static

void

Writes a Uri to a Parcel.

[Expand]

Inherited Methods

3e54f4822052f69722b015cabe630b87.png

From class

java.lang.Object

Creates and returns a copy of this Object.

boolean

Compares this instance with the specified object and indicates if they

are equal.

void

Invoked when the garbage collector has detected that this instance is no longer reachable.

final

Class>

Returns the unique instance of

int

Returns an integer hash code for this object.

final

void

Causes a thread which is waiting on this object's monitor (by means of

calling one of the wait() methods) to be woken up.

final

void

Causes all threads which are waiting on this object's monitor (by means

of calling one of the wait() methods) to be woken up.

Returns a string containing a concise, human-readable description of this

object.

final

void

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

final

void

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the

specified timeout expires.

final

void

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the

specified timeout expires.

3e54f4822052f69722b015cabe630b87.png

From interface

android.os.Parcelable

abstract

int

Describe the kinds of special objects contained in this Parcelable's

marshalled representation.

abstract

void

Flatten this object in to a Parcel.

3e54f4822052f69722b015cabe630b87.png

From interface

java.lang.Comparable

abstract

int

Compares this object to the specified object to determine their relative

order.

Fields

public

static

final

Creator

CREATOR

Reads Uris from Parcels.

public

static

final

Uri

EMPTY

The empty URI, equivalent to "".

Public Methods

public

abstract

Uri.Builder

buildUpon

()

Constructs a new builder, copying the attributes from this Uri.

public

int

compareTo

(Uri other)

Compares the string representation of this Uri with that of

another.

public

static

String

decode

Decodes '%'-escaped octets in the given string using the UTF-8 scheme.

Replaces invalid octets with the unicode replacement character

("\\uFFFD").

Parameters

sencoded string to decode

Returns

the given string with escaped octets decoded, or null if

s is null

public

static

String

encode

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.

Parameters

sstring to encode

allowset of additional characters to allow in the encoded form,

null if no characters should be skipped

Returns

an encoded version of s suitable for use as a URI component,

or null if s is null

public

static

String

encode

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.

Parameters

sstring to encode

Returns

an encoded version of s suitable for use as a URI component,

or null if s is null

public

boolean

equals

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.

Parameters

othe object to compare this instance with.

Returns

true if the specified object is equal to this Object; false otherwise.

public

static

Uri

fromFile

(File file)

Creates a Uri from a file. The URI has the form

"file://". Encodes path characters with the exception of

'/'.

Example: "file:///tmp/android.txt"

Returns

a Uri for the given file

Throws

public

static

Uri

fromParts

(String scheme, String ssp, String fragment)

Creates an opaque Uri from the given components. Encodes the ssp

which means this method cannot be used to create hierarchical URIs.

Parameters

schemeof the URI

sspscheme-specific-part, everything between the

scheme separator (':') and the fragment separator ('#'), which will

get encoded

fragmentfragment, everything after the '#', null if undefined,

will get encoded

Returns

Uri composed of the given scheme, ssp, and fragment

Throws

if scheme or ssp is null

public

abstract

String

getAuthority

()

Gets the decoded authority part of this URI. For

server addresses, the authority is structured as follows:

[ userinfo '@' ] host [ ':' port ]

Examples: "google.com", "bob@google.com:80"

Returns

the authority for this URI or null if not present

public

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. "false" and "0" are interpreted as false, everything

else is interpreted as true.

Parameters

keywhich will be decoded

defaultValuethe default value to return if there is no query parameter for key

Returns

the boolean interpretation of the query parameter key

public

abstract

String

getEncodedAuthority

()

Gets the encoded authority part of this URI. For

server addresses, the authority is structured as follows:

[ userinfo '@' ] host [ ':' port ]

Examples: "google.com", "bob@google.com:80"

Returns

the authority for this URI or null if not present

public

abstract

String

getEncodedFragment

()

Gets the encoded fragment part of this URI, everything after the '#'.

Returns

the encoded fragment or null if there isn't one

public

abstract

String

getEncodedPath

()

Gets the encoded path.

Returns

the encoded path, or null if this is not a hierarchical URI

(like "mailto:nobody@google.com") or the URI is invalid

public

abstract

String

getEncodedQuery

()

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".

Returns

the encoded query or null if there isn't one

public

abstract

String

getEncodedSchemeSpecificPart

()

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"

Returns

the decoded scheme-specific-part

public

abstract

String

getEncodedUserInfo

()

Gets the encoded user information from the authority.

For example, if the authority is "nobody@google.com", this method will

return "nobody".

Returns

the user info for this URI or null if not present

public

abstract

String

getFragment

()

Gets the decoded fragment part of this URI, everything after the '#'.

Returns

the decoded fragment or null if there isn't one

public

abstract

String

getHost

()

Gets the encoded host from the authority for this URI. For example,

if the authority is "bob@google.com", this method will return

"google.com".

Returns

the host for this URI or null if not present

public

abstract

String

getLastPathSegment

()

Gets the decoded last segment in the path.

Returns

the decoded last segment or null if the path is empty

public

abstract

String

getPath

()

Gets the decoded path.

Returns

the decoded path, or null if this is not a hierarchical URI

(like "mailto:nobody@google.com") or the URI is invalid

public

abstract

List

getPathSegments

()

Gets the decoded path segments.

Returns

decoded path segments, each without a leading or trailing '/'

public

abstract

int

getPort

()

Gets the port from the authority for this URI. For example,

if the authority is "google.com:80", this method will return 80.

Returns

the port for this URI or -1 if invalid or not present

public

abstract

String

getQuery

()

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".

Returns

the decoded query or null if there isn't one

public

String

getQueryParameter

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

Parameters

keywhich will be encoded

Returns

the decoded value or null if no parameter is found

Throws

getQueryParameterNames

()

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.

Returns

a set of decoded names

Throws

if this isn't a hierarchical URI

getQueryParameters

Searches the query string for parameter values with the given key.

Parameters

keywhich will be encoded

Returns

a list of decoded values

Throws

public

abstract

String

getScheme

()

Gets the scheme of this URI. Example: "http"

Returns

the scheme or null if this is a relative URI

public

abstract

String

getSchemeSpecificPart

()

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"

Returns

the decoded scheme-specific-part

public

abstract

String

getUserInfo

()

Gets the decoded user information from the authority.

For example, if the authority is "nobody@google.com", this method will

return "nobody".

Returns

the user info for this URI or null if not present

public

int

hashCode

()

Hashes the encoded string represention of this Uri consistently with

Returns

this object's hash code.

public

boolean

isAbsolute

()

Returns true if this URI is absolute, i.e. if it contains an

explicit scheme.

Returns

true if this URI is absolute, false if it's relative

public

abstract

boolean

isHierarchical

()

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.

public

boolean

isOpaque

()

Returns true if this URI is opaque like "mailto:nobody@google.com". The

scheme-specific part of an opaque URI cannot start with a '/'.

public

abstract

boolean

isRelative

()

Returns true if this URI is relative, i.e. if it doesn't contain an

explicit scheme.

Returns

true if this URI is relative, false if it's absolute

public

Uri

normalizeScheme

()

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.

Returns

normalized Uri (never null)

public

static

Uri

parse

(String uriString)

Creates a Uri which parses the given encoded URI string.

Parameters

uriStringan RFC 2396-compliant, encoded URI

Returns

Uri for this given uri string

Throws

if uriString is null

public

abstract

String

toString

()

Returns the encoded string representation of this URI.

Example: "http://google.com/"

Returns

a printable representation of this object.

public

static

Uri

withAppendedPath

(Uri baseUri, String pathSegment)

Creates a new Uri by appending an already-encoded path segment to a

base Uri.

Parameters

baseUriUri to append path segment to

pathSegmentencoded path segment to append

Returns

a new Uri based on baseUri with the given segment appended to

the path

Throws

public

static

void

writeToParcel

(Parcel out, Uri uri)

Writes a Uri to a Parcel.

Parameters

outparcel to write to

urito write, can be null

Except as noted, this content is licensed under Apache 2.0.

For details and restrictions, see the Content License.

Android 4.4 r1 —

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值