What is an URI in android

29
我最近遇到了一个对我来说毫无意义的Android对象。我不明白URI是什么意思。
我查看了官方文档,上面写着:
不可变的URI引用。URI引用包括一个URI和一个片段,即在“#”后面的URI组件。构建和解析符合RFC 2396的URI引用。
问题是,你不能用一个URI来解释URI是什么!我完全困惑了。
我做了一些研究,找到了这篇文章。但是它说:
Uri什么都不做。
有人能解释一下这是什么意思吗?

3
https://en.wikipedia.org/wiki/Uniform_resource_identifier - Karakuri
10
URI类似于互联网上的URL(统一资源定位符),但范围更广。例如:file:///something.txthttp://www.example.com/ftp://example.com。冒号前的不同字符串表示不同的协议/处理程序。在Android中,URI用于指向其他应用程序、操作等,例如tel:+44123456789。查看这里,了解使用Uri拨打电话的示例。 - Basic
可能是URI、URL和URN有什么区别?的重复。 - StephenG
这个RFC文档可能会有所帮助。 - Sahil Singh
3个回答

36
  1. 问题:什么是“URI”?

    答案:技术上,“URI”的含义在 RFC 2396中有定义:

统一资源标识符(URI)是一个紧凑的字符序列,用于标识抽象或物理资源。

  1. 问题:什么是Android“URI”类?

    答案:这里是 android.net.Uri的Javadoc文档。

  2. 问题:但我们为什么需要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方案标识各种不同类型的信息对象,在协议中扮演不同的角色。一些标识服务、连接端点等,但基本的底层架构概念是信息对象 - 也称为通用文档。这些可以由比特串表示。信息对象传达某些东西 - 它可能是艺术、诗歌、传感器值或数学方程。


我未能回答的一个问题是:什么是Android的“URI引用”?请查看Uri.Builder的“类概述”部分,链接在此处:http://developer.android.com/reference/android/net/Uri.Builder.html。这也回答了关于“URI”与“URI片段”的问题。 - paulsm4

5

URI(统一资源标识符),如其名称所示,用于标识资源(无论是文本页面、视频或音频剪辑、静态或动画图像还是程序)。

URI的最常见形式是网页地址,它是URI的一种特定形式或子集,称为统一资源定位符(URL)。

Android使用URI字符串作为内容提供程序中请求数据(例如检索联系人列表)和请求操作(例如在浏览器中打开网页)的基础。


1
我正在添加关于缩写URI的RFC细节以及一些使用示例:

From,
http://www.faqs.org/rfcs/rfc2396.html

这份文档更新并合并了"统一资源定位符"[RFC1738]和"相对统一资源定位符"[RFC1808],以定义一个通用的语法来表示所有URI。
另外,

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协议


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接