- 語法:
<grant-uri-permission android:path="string" android:pathPattern="string" android:pathPrefix="string" />
- 包含於:
<provider>
- 說明:
- 指定父項內容供應者有權存取的應用程式資料子集。子集內容會以
content:
URI 的路徑部分表示 URI 的授權部分會識別 內容供應器。 如授予相關權限,供應者方原本無權存取資料的用戶端將可存取一次。如果內容供應者的
grantUriPermissions
屬性為true
,則可授予供應者名下所有資料的存取權限。不過,如果該屬性是false
,則只能針對此元素指定的資料子集授予權限。供應者可包含任意數量的<grant-uri-permission>
元素。每個元素都只能指定一個路徑,使用三種可能屬性中的一種。如要瞭解如何授予權限,請參閱
<intent-filter>
元素的grantUriPermissions
屬性。 - 屬性:
android:path
android:pathPrefix
android:pathPattern
- 標識可授權資料子集的路徑。
path
屬性會指定完整路徑。 您只能針對該路徑標識的資料子集授予權限。pathPrefix
屬性會指定路徑的初始部分。 您可以針對路徑初始部分相同的所有資料子集授予權限。pathPattern
屬性會指定完整路徑,但其中 可包含下列萬用字元:- 星號 (
*
),代表前一個字元出現 0 次以上的序列。 半形句號後面加上星號 (
.*
),代表 0 個字元以上的任何序列。
由於在從 XML 讀取字串時,系統會使用「
\
」做為逸出字元,因此在剖析為模式之前,您必須先進行雙重逸出。例如,將常值「*
」寫入為「\\*
」,常值「\
」寫入為\\\
。如要進一步瞭解這些模式,請參閱
PatternMatcher
類別中PATTERN_LITERAL
、PATTERN_PREFIX
和PATTERN_SIMPLE_GLOB
的說明。 - 星號 (
- 導入版本:
- API 級別 1
- 另請參閱:
<provider>
元素的grantUriPermissions
屬性
<grant-uri-permission>
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# <grant-uri-permission\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cgrant-uri-permission android:path=\"string\"\n android:pathPattern=\"string\"\n android:pathPrefix=\"string\" /\u003e\n ```\n\ncontained in:\n: [\u003cprovider\u003e](/guide/topics/manifest/provider-element)\n\ndescription:\n: Specifies the subsets of app data that the parent content provider\n has permission to access. Data subsets are indicated by the path part of a\n `content:` URI. The authority part of the URI identifies the\n content provider.\n Granting permission is a way of enabling clients of the provider that don't\n normally have permission to access its data to overcome that restriction on\n a one-time basis.\n\n\n If a content provider's [grantUriPermissions](/guide/topics/manifest/provider-element#gprmsn)\n attribute is `true`, permission can be granted for any of the data under\n the provider's purview. However, if that attribute is `false`, permission\n is granted only to data subsets that are specified by this element.\n A provider can contain any number of `\u003cgrant-uri-permission\u003e` elements.\n Each one can specify only one path, using one of the three possible attributes.\n\n\n For information about how permission is granted, see the\n [\u003cintent-filter\u003e](/guide/topics/manifest/intent-filter-element) element's\n [grantUriPermissions](/guide/topics/manifest/provider-element#gprmsn) attribute.\n\nattributes:\n:\n\n `android:path`\n\n `android:pathPrefix`\n\n `android:pathPattern`\n : A path identifying the data subset or subsets that permission can be\n granted for. The `path` attribute specifies a complete path.\n Permission can granted only to the particular data subset identified\n by that path.\n\n \u003cbr /\u003e\n\n\n The `pathPrefix` attribute specifies the initial part of a path.\n Permission can be granted to all data subsets with paths that share that\n initial part.\n The `pathPattern` attribute specifies a complete path, but one\n that can contain the following wildcards:\n\n - An asterisk (`*`) matches a sequence of zero to many occurrences of the immediately preceding character.\n - A period followed by an asterisk (`.*`) matches any sequence of\n zero to many characters.\n\n\n Because `\\` is used as an escape character when the string is read\n from XML, before it is parsed as a pattern, you need to double-escape.\n For example, a literal `*` is written as `\\\\*` and a\n literal `\\` is written as `\\\\\\`.\n\n\n For more information about these types of patterns, see the descriptions of\n [PATTERN_LITERAL](/reference/android/os/PatternMatcher#PATTERN_LITERAL),\n [PATTERN_PREFIX](/reference/android/os/PatternMatcher#PATTERN_PREFIX), and\n [PATTERN_SIMPLE_GLOB](/reference/android/os/PatternMatcher#PATTERN_SIMPLE_GLOB) in the\n [PatternMatcher](/reference/android/os/PatternMatcher) class.\n\nintroduced in:\n: API level 1\n\nsee also:\n:\n [grantUriPermissions](/guide/topics/manifest/provider-element#gprmsn)\n attribute of the\n [\u003cprovider\u003e](/guide/topics/manifest/provider-element)\n element"]]