Android中的URI介紹

來源:互聯網
上載者:User

就Android平台而言,URI主要分三個部分:scheme, authority and path。其中authority又分為host和 port。格式如下:

scheme://host:port/path

舉個實際的例子:

content://com.example.project:200/folder/subfolder/etc

\---------/  \---------------------------/ \---/ \--------------------------/

scheme                 host               port        path

           \--------------------------------/

                     authority

現在 大家應該知道data flag中那些屬性的含義了吧,看下data flag

<data android:host="string"

 android:mimeType="string"

 android:path="string"

 android:pathPattern="string"

 android:pathPrefix="string"

 android:port="string"

 android:scheme="string" />

1.Uri

通用資源標誌符(Universal Resource Identifier, 簡稱"URI")。

Uri代表要操作的資料,Android上可用的每種資源 - 映像、視頻片段等都可以用Uri來表示。

URI一般由三部分組成:

訪問資源的命名機制。

存放資源的主機名稱。

資源自身的名稱,由路徑表示。

Android的Uri由以下三部分組 成: "content://"、資料的路徑、標示ID(可選)

舉些例子,如:

所有連絡人的 Uri: content://contacts/people

某個連絡人的Uri: content://contacts/people/5

所有圖 片Uri: content://media/external

某個圖片的Uri: content://media/external/images/media/4

我們很經常需要解析Uri,並從Uri中擷取資料。

Android系統提供了兩個用於操作Uri的工具類,分別為UriMatcher 和ContentUris 。

雖然這 兩類不是非常重要,但是掌握它們的使用,會便於我們的開發工作。

下面就一起看一下這兩個類的作 用。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.