- 語法:
<data android:scheme="string" android:host="string" android:port="string" android:path="string" android:pathPattern="string" android:pathPrefix="string" android:mimeType="string" />
- 包含於:
<intent-filter>
- 說明:
- 在資料篩選器中加入資料規格。規格可以僅是一個資料類型 (
mimeType
屬性)、僅一個 URI 或既是資料類型又是 URI。URI 透過其每個部分的不同屬性指定:<scheme>://<host>:<port>[<path>|<pathPrefix>|<pathPattern>]
這些指定網址格式的屬性是可選的,但也彼此相依:
同一個
<intent-filter>
元素中包含的所有<data>
元素都有助於同一個篩選器。舉例來說,下列篩選器規格,<intent-filter . . . > <data android:scheme="something" android:host="project.example.com" /> . . . </intent-filter>
相當於下列項目:
<intent-filter . . . > <data android:scheme="something" /> <data android:host="project.example.com" /> . . . </intent-filter>
您可以在
<intent-filter>
中放入任意數量的<data>
元素,藉此提供多個資料選項。沒有任何預設值的屬性。如需瞭解意圖篩選器的運作方式 (包括意圖物件如何與篩選器比對的規則),請參閱其他文件:意圖和意圖篩選器。另請參閱資訊清單檔案總覽中的意圖篩選器一節。
- 屬性:
android:scheme
- URI 配置部分。這是指定 URI 的基本必要屬性;請為篩選器設定至少一個
scheme
屬性,否則沒有其他的 URI 屬性就沒有意義。指定的配置不含結尾的冒號 (例如
http
,而不是http:
)。如果篩選器已設定資料類型 (
mimeType
屬性),但沒有配置,則系統會採用content:
和file:
配置。注意:與 RFC 不同,Android 架構中的配置比對有大小寫之分。因此,您應一律使用小寫英文字母指定配置。
android:host
- URI 授權的主機部分。除非為篩選器也指定
scheme
屬性,否則這個屬性不具任何意義。如要比對多個子網域,請使用星號 (*
) 來比對主機中的零個或多個字元。例如,主機*.google.com
會比對www.google.com
、.google.com
和developer.google.com
。星號必須是主機屬性的第一個半形字元。舉例來說,主機
google.co.*
無效,因為星號萬用半形字元不是第一個半形字元。注意:Android 架構中的主機名稱比對有大小寫之分,與正式的 RFC 不同。因此,建議您一律使用小寫英文字母指定主機名稱。
android:port
- URI 授權的通訊埠部分。只有在篩選器也指定了
scheme
和host
屬性時,這個屬性才有意義。 android:path
android:pathPrefix
android:pathPattern
- URI 路徑部分的開頭必須是 /。
path
屬性會指定與意圖物件中完整路徑相符的完整路徑。pathPrefix
屬性指定只與意圖物件路徑中初始部分相符的部分路徑。pathPattern
屬性會指定與意圖物件中完整路徑相符的完整路徑,但可包含下列萬用半形字元:- 星號 (「
*
」) 會將一個 0 序列比對到多次出現的前一個半形字元。 - 星號後跟一個點 (「
.*
」) 會將所有 0 序列比對到許多半形字元。
由於在從 XML 讀取字串時,會使用「
\
」做為逸出半形字元 (在其剖析為模式前),因此您需要進行雙重逸出:例如,常值「*
」將寫入為「\\*
」,常值「\
」寫入為「\\\\
」。當以 Java 程式碼建構字串時,寫入規則基本相同。如要進一步瞭解這三種模式,請參閱
PatternMatcher
類別中PATTERN_LITERAL
、PATTERN_PREFIX
和PATTERN_SIMPLE_GLOB
的說明。 - 星號 (「
android:mimeType
- MIME 媒體類型,例如
image/jpeg
或audio/mpeg4-generic
。子類型可以是星號萬用字元 (*
),表示任何子類型相符情況。意圖篩選器宣告的
<data>
只包含android:mimeType
屬性是很常見的情況。注意:Android 架構中的 MIME 類型比對必須區分大小寫,與正式的 RFC MIME 類型不同。因此,您應一律使用小寫英文字母指定 MIME 類型。
- 導入版本:
- API 級別 1
- 另請參閱:
<action>
<category>
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-05-16 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Translation issue"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]