问题:什么是“URI”?
答案:技术上,“URI”的含义在 RFC 2396中有定义:
统一资源标识符(URI)是一个紧凑的字符序列,用于标识抽象或物理资源。
问题:什么是Android“URI”类?
答案:这里是 android.net.Uri的Javadoc文档。
问题:但我们为什么需要Android的“URI”类?
答案:请查看Android文档中的“内容提供程序”部分:
http://developer.android.com/guide/topics/providers/content-providers.html
内容提供者管理对一组结构化数据的访问。它们封装数据并提供定义数据安全性的机制。内容提供者是标准接口,将一个进程中的数据与另一个进程中运行的代码连接起来。
例如...
public final ContentProviderClient acquireContentProviderClient (Uri uri)
返回一个与服务于uri处内容的ContentProvider相关联的ContentProviderClient,必要时启动该提供程序。
如果你感到好奇,这里是Tim Berners-Lee关于URI的看法(他是发明URI的人 ;)):
http://www.w3.org/DesignIssues/Axioms.html#uri
统一资源标识符
Web是一个通用信息空间。它是一个空间,因为其中的事物有一个地址。这篇文章的主题是“地址”、“名称”或者我们在这里称之为标识符。它们被称为统一资源标识符(URIs)。
如果一个信息对象具有URI,则它就“在Web上”。具有URI的对象有时被称为“第一类对象”(FCOs)。当任何具有价值和身份的信息对象都是第一类对象时,Web运作最佳。如果某物没有URI,则无法引用它,Web的能力也会因此减弱。
通过“通用”,我指的是Web被声明为可以原则上包含网络可访问的每一位信息。它旨在能够包括现有的信息系统(如FTP),并且未来能够简单地扩展以包括任何新的信息系统。
URI方案标识各种不同类型的信息对象,在协议中扮演不同的角色。一些标识服务、连接端点等,但基本的底层架构概念是信息对象 - 也称为通用文档。这些可以由比特串表示。信息对象传达某些东西 - 它可能是艺术、诗歌、传感器值或数学方程。
URI(统一资源标识符),如其名称所示,用于标识资源(无论是文本页面、视频或音频剪辑、静态或动画图像还是程序)。
URI的最常见形式是网页地址,它是URI的一种特定形式或子集,称为统一资源定位符(URL)。
Android使用URI字符串作为内容提供程序中请求数据(例如检索联系人列表)和请求操作(例如在浏览器中打开网页)的基础。
From,
http://www.faqs.org/rfcs/rfc2396.html
1.1 Overview of URI
URI are characterized by the following definitions:
Uniform Uniformity provides several benefits: it allows different types of resource identifiers to be used in the same context, even when the mechanisms used to access those resources may differ; it allows uniform semantic interpretation of common syntactic conventions across different types of resource identifiers; it allows introduction of new types of resource identifiers without interfering with the way that existing identifiers are used; and, it allows the identifiers to be reused in many different contexts, thus permitting new applications or protocols to leverage a pre-existing, large, and widely-used set of resource identifiers. Resource A resource can be anything that has identity. Familiar examples include an electronic document, an image, a service (e.g., "today's weather report for Los Angeles"), and a collection of other resources. Not all resources are network "retrievable"; e.g., human beings, corporations, and bound books in a library can also be considered resources. The resource is the conceptual mapping to an entity or set of entities, not necessarily the entity which corresponds to that mapping at any particular instance in time. Thus, a resource can remain constant even when its content---the entities to which it currently corresponds---changes over time, provided that the conceptual mapping is not changed in the process. Identifier An identifier is an object that can act as a reference to something that has identity. In the case of URI, the object is a sequence of characters with a restricted syntax.
以下是一些常用的URI示例:
1.3. 示例URI
以下示例展示了一些常见使用的URI。
ftp://ftp.is.co.za/rfc/rfc1808.txt -- 用于文件传输协议服务的ftp协议
gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles -- 用于Gopher和Gopher+协议服务的gopher协议
http://www.math.uio.no/faq/compression-faq/part1.html -- 用于超文本传输协议服务的http协议
mailto:mduerst@ifi.unizh.ch -- 用于电子邮件地址的mailto协议
news:comp.infosystems.www.servers.unix -- 用于USENET新闻组和文章的news协议
telnet://melvyl.ucop.edu/ -- 通过TELNET协议进行交互式服务的telnet协议
file:///something.txt
,http://www.example.com/
,ftp://example.com
。冒号前的不同字符串表示不同的协议/处理程序。在Android中,URI用于指向其他应用程序、操作等,例如tel:+44123456789
。查看这里,了解使用Uri拨打电话的示例。 - Basic