- 语法:
<grant-uri-permission android:path="string" android:pathPattern="string" android:pathPrefix="string" />
- 包含于:
<provider>
- 说明:
- 指定父 content provider 有权访问的应用数据的子集。数据子集由
content:
URI 的路径部分指示。URI 的权威部分标识 content provider。通过授予权限,可以使通常无权访问其数据的提供程序的客户端能够一次克服该限制。如果 content provider 的
grantUriPermissions
属性为true
,则可以为提供程序权限下的任何数据授予权限。不过,如果该属性为false
,则只能向此元素指定的数据子集授予权限。提供程序可以包含任意数量的<grant-uri-permission>
元素。每个元素只能指定一个路径,使用三个可能属性中的一个。如需了解权限是如何授予的,请参阅
<intent-filter>
元素的grantUriPermissions
属性。 - 属性:
android:path
android:pathPrefix
android:pathPattern
- 标识可向其授予权限的一个或多个数据子集的路径。
path
属性指定完整路径。只能授予对由该路径标识的特定数据子集的相应权限。pathPrefix
属性用于指定路径的初始部分。可以授予对路径共有此初始部分的所有数据子集的相应权限。pathPattern
属性指定完整路径,但可以包含以下通配符:- 星号 (
*
) 匹配由前面紧挨字符的零到多个重复项所组成的序列。 英文句点后跟星号 (
.*
) 匹配由零到多个字符构成的任意序列。
由于在从 XML 读取字符串时(在将其解析为模式之前)将
\
用作转义字符,因此您需要进行双重转义。例如,字面量*
编写为\\*
,字面量\
编写为\\\
。如需详细了解这些类型的模式,请参阅
PatternMatcher
类中的PATTERN_LITERAL
、PATTERN_PREFIX
和PATTERN_SIMPLE_GLOB
的说明。 - 星号 (
- 引入于:
- API 级别 1
- 另请参阅:
<provider>
元素的grantUriPermissions
属性
<grant-uri-permission>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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"]]