android.net.Uri 简介 API
Posted 白乾涛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android.net.Uri 简介 API相关的知识,希望对你有一定的参考价值。
android.net.Uri 简介
public abstract class android.net.Uri extends Object implements Parcelable, Comparable<Uri>
Uri 的组成及示例
scheme://host:port/path?query
<scheme>://<authority><absolute path>?<query>#<fragment>
- 1)scheme:访问资源的命名机制,通过这个可以获悉Uri的具体资源存在形式,如http、content、file、market等
- 2)authority:存放资源的主机名。authority 应该是scheme:// 之后到第一次出现 ‘/’ 或‘?’ 或‘#’之间的string
- 3)path:authority之后第一个 ‘/’ 开始到 ‘?’ 或 ‘#’ 之前的string(包含‘/‘)
- 4)query:‘?‘ 号之后 ‘#‘ 号之前的string(类似get请求时的提交的参数)
打开一个网页 http://blog.3gstdy.com/
发送短信 smsto:10086
发送彩信(相当于发送带附件的短信) content://media/external/images/media/23
打开地图并定位到一个点 geo:52.76,-79.0342
拨打电话 tel:10086
打开文件 file:///sdcard/download/everything.mp3
打开发邮件界面 mailto:[email protected]
寻找某个应用 market://search?q=pname:pkg_name
显示地图(经纬度) geo:39.9,116.3
路径规划 http://maps.google .com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en
<data android:host="string"
android:mimeType="string"
android:path="string"
android:pathPattern="string"
android:pathPrefix="string"
android:port="string"
android:scheme="string" />
get**和getEncoded**等方法的区别
for (int i = 0; i < bytesLength; i++) {
encoded.append(‘%‘);
encoded.append(HEX_DIGITS[(bytes[i] & 0xf0) >> 4]);
encoded.append(HEX_DIGITS[bytes[i] & 0xf]);
}
Uri uri = new Uri.Builder().path("包青天").build();
Log.i("bqt", uri.getPath() + " " + uri.getEncodedPath());//包青天 %E5%8C%85%E9%9D%92%E5%A4%A9
Uri uri1 = new Uri.Builder().encodedPath("%E5%8C%85%E9%9D%92%E5%A4%A9").build();
Log.i("bqt", uri1.getPath() + " " + uri1.getEncodedPath());//包青天 %E5%8C%85%E9%9D%92%E5%A4%A9
Uri uri2 = new Uri.Builder().path("bqt").build();
Log.i("bqt", uri2.getPath() + " " + uri2.getEncodedPath());//bqt bqt
Uri uri3 = new Uri.Builder().encodedPath("包青天").build();
Log.i("bqt", uri3.getPath() + " " + uri3.getEncodedPath());//包青天 包青天
android.net.Uri【API】
- static String decode(String s) Decodes ‘%‘-escaped octets in the given string 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.
- static String encode(String s) Encodes characters in the given string as ‘%‘-escaped octets using the UTF-8 scheme.
- 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.
- static Uri parse(String uriString) Creates a Uri which parses the given encoded URI string.
- static Uri withAppendedPath(Uri baseUri, String pathSegment) Creates a new Uri by appending an already-encoded path segment to a base 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.
- 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.
- boolean isAbsolute() Returns true if this URI is absolute, i.e. if it contains an explicit明确的 scheme.
- boolean isOpaque() Returns true if this URI is opaque不透明的、模糊的 like "mailto:[email protected]".
- Uri normalizeScheme() Return an equivalent等价的 URI with a lowercase小写的 scheme component组成. normalize:使正常化、使标准化
- abstract String getEncodedAuthority() Gets the encoded/decoded authority part of this URI.
- abstract String getEncodedFragment() Gets the encoded/decoded fragment part of this URI, everything after the ‘#‘.
- abstract String getEncodedPath() Gets the encoded/decoded path.
- abstract String getEncodedQuery() Gets the encoded/decoded query component from this URI.
- abstract String getHost() Gets the encoded host from the authority for this URI.
- abstract int getPort() Gets the port from the authority for this URI.
- abstract String getScheme() Gets the scheme of this URI. Example: "http"
- abstract String getEncodedUserInfo() Gets the encoded user information from the authority.
- abstract String getLastPathSegment() Gets the decoded last segment in the path.
- abstract List<String> getPathSegments() Gets the decoded path segments.
- abstract String getSchemeSpecificPart() Gets the scheme-specific part of this URI, i.e. everything between the scheme separator ‘:‘ and the fragment separator ‘#‘.
- abstract String getEncodedSchemeSpecificPart() Gets the scheme-specific part of this URI, i.e. everything between the scheme separator ‘:‘ and the fragment separator ‘#‘.
- abstract Uri.Builder buildUpon() Constructs a new builder, copying the attributes from this Uri.
- abstract boolean isHierarchical() Returns true if this URI is hierarchical like "http://google.com".
- abstract boolean isRelative() Returns true if this URI is relative, i.e. if it doesn‘t contain an explicit明确的 scheme.
- abstract String toString() Returns the encoded string representation of this URI.
Uri.Builder【文档及API】
<scheme>://<authority><absolute path>?<query>#<fragment>
<relative or absolute path>?<query>#<fragment>
//<authority><absolute path>?<query>#<fragment>
<scheme>:<opaque part>#<fragment>
- Uri build() Constructs a Uri with the current attributes.
- Uri.Builder authority(String authority) Encodes and sets the authority.
- Uri.Builder encodedAuthority(String authority) Sets the previously encoded authority.
- Uri.Builder path(String path) Sets the path.
- Uri.Builder encodedPath(String path) Sets the previously encoded path.
- Uri.Builder appendPath(String newSegment) Encodes the given segment and appends it to the path.
- Uri.Builder appendEncodedPath(String newSegment) Appends the given segment片段、分割 to the path.
- Uri.Builder query(String query) Encodes and sets the query.
- Uri.Builder encodedQuery(String query) Sets the previously encoded query.
- Uri.Builder appendQueryParameter(String key, String value) Encodes the key and value and then appends the parameter to the query string.
- Uri.Builder clearQuery() Clears the the previously set query.
- Uri.Builder scheme(String scheme) Sets the scheme.
- Uri.Builder fragment(String fragment) Encodes and sets the fragment.
- Uri.Builder encodedFragment(String fragment) Sets the previously encoded fragment.
- Uri.Builder opaquePart(String opaquePart) Encodes and sets the given opaque scheme-specific-part.
- Uri.Builder encodedOpaquePart(String opaquePart) Sets the previously encoded opaque scheme-specific-part.
以上是关于android.net.Uri 简介 API的主要内容,如果未能解决你的问题,请参考以下文章
错误记录Oboe / AAudio 播放器报错 ( onEventFromServer - AAUDIO_SERVICE_EVENT_DISCONNECTED - FIFO cleared )(代码片
嵌入式开发裸机引导操作系统和ARM 内存操作 ( DRAM SRAM 类型 简介 | Logical Bank | 内存地址空间介绍 | 内存芯片连接方式 | 内存初始化 | 汇编代码示例 )(代码片
Android Api 27 在 Android 8.0 上出现 Only fullscreen opaque activities can request orientation 的解决情况(代码片
Android Studio编译OsmAnd出现警告:GeoPointParserUtil.java使用或覆盖了已过时的 API。有关详细信息请使用-Xlint:deprecation重新编译(代码片
Spring MVC @Controller中转发或者重定向到其他页面的信息怎么携带和传递(Servlet API对象)HttpServletRequestHttpServletRespose(代码片
GlobalGetAtomName GlobalDeleteAtom 引用 WinAPI: AddAtomDeleteAtomFindAtomGetAtomNameGlobalAddAtom(代码片