- 语法:
<path-permission android:path="string" android:pathPrefix="string" android:pathPattern="string" android:permission="string" android:readPermission="string" android:writePermission="string" />
- 包含于:
<provider>
- 说明:
- 定义 content provider 中特定数据子集的路径和所需权限。您可以多次指定此元素,以提供多个路径。
- 属性:
android:path
- content provider 数据子集的完整 URI 路径。只能授予对由此路径标识的特定数据的相应权限。用于提供搜索建议内容时,会附加有
/search_suggest_query
。 android:pathPrefix
- content provider 数据子集的 URI 路径的初始部分。可以授予对路径共有此初始部分的所有数据子集的相应权限。
android:pathPattern
- content provider 数据子集的完整 URI 路径,但可以使用以下通配符:
- 星号 (
*
)。这匹配由前面紧挨字符的零到多个重复项所组成的序列。 - 英文句点后跟星号 (
.*
)。这匹配由零或多个字符构成的任意序列。
由于在从 XML 读取字符串时(在将其解析为模式之前)将反斜杠 (
\
) 用作转义字符,因此您需要进行双重转义。例如,字面量*
写为“\\*
”,字面量\
写为“\\\
”。这与您在使用 Java 编程语言构造字符串时执行的操作相同。如需详细了解这些类型的模式,请参阅
PatternMatcher
类中的PATTERN_LITERAL
、PATTERN_PREFIX
和PATTERN_SIMPLE_GLOB
的说明。 - 星号 (
android:permission
- 客户端要读取或写入 content provider 的数据而需具备的权限的名称。您可以使用此属性来方便地设置适用于读取和写入的单项权限。不过,
readPermission
和writePermission
属性优先于此属性。 android:readPermission
- 客户端要查询 content provider 而需具备的权限。
android:writePermission
- 客户端要对由 content provider 控制的数据进行更改而需具备的权限。
- 引入于:
- API 级别 4
- 另请参阅:
SearchManager
Manifest.permission
- 安全提示
<路径权限>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <path-permission\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cpath-permission android:path=\"string\"\n android:pathPrefix=\"string\"\n android:pathPattern=\"string\"\n android:permission=\"string\"\n android:readPermission=\"string\"\n android:writePermission=\"string\" /\u003e\n ```\n\ncontained in:\n: [\u003cprovider\u003e](/guide/topics/manifest/provider-element)\n\ndescription:\n: Defines the path and required permissions for a specific subset of data\n within a content provider. This element can be\n specified multiple times to supply multiple paths.\n\nattributes:\n:\n\n `android:path`\n : A complete URI path for a subset of content provider data.\n Permission can be granted only to the particular data identified by this path.\n When used to provide search suggestion content, it is appended\n with `/search_suggest_query`.\n\n `android:pathPrefix`\n : The initial part of a URI path for a subset of content provider data.\n Permission can be granted to all data subsets with paths that share this initial part.\n\n `android:pathPattern`\n : A complete URI path for a subset of content provider data,\n but one that can use the following wildcards:\n\n - An asterisk (`*`). This matches a sequence of zero to many occurrences of the immediately preceding character.\n - A period followed by an asterisk (`.*`). This matches any sequence of zero or more characters.\n\n\n Because the backslash (`\\`) 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 \"`\\\\\\`\". This is\n the same as what you write if constructing the string in the Java programming language.\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\n `android:permission`\n : The name of a permission that clients need in order to read or write the\n content provider's data. This attribute is a convenient way of setting a\n single permission for both reading and writing. However, the\n `readPermission` and\n `writePermission` attributes take precedence\n over this one.\n\n `android:readPermission`\n : A permission that clients need in order to query the content provider.\n\n `android:writePermission`\n : A permission that clients need in order to make changes to the data controlled by the content provider.\n\nintroduced in:\n: API level 4\n\nsee also:\n: [SearchManager](/reference/android/app/SearchManager)\n: [Manifest.permission](/reference/android/Manifest.permission)\n: [Security tips](/guide/topics/security/security)"]]