- cú pháp:
<permission android:description="string resource" android:icon="drawable resource" android:label="string resource" android:name="string" android:permissionGroup="string" android:protectionLevel=["normal" | "dangerous" | "signature" | ...] />
- có trong:
<manifest>
- mô tả:
- Khai báo quyền bảo mật dùng để giới hạn quyền truy cập vào các thành phần hoặc tính năng cụ thể của ứng dụng này hoặc các ứng dụng khác. Để biết thêm thông tin về cách hoạt động của các quyền, hãy xem phần Quyền trong trang tổng quan về tệp kê khai ứng dụng và Mẹo bảo mật.
- thuộc tính:
android:description
- Nội dung mô tả quyền mà người dùng có thể đọc được, thường dài hơn và chứa nhiều thông tin hơn so với nhãn. Chẳng hạn, nội dung này có thể hiển thị để giải thích về quyền cho người dùng khi người dùng được yêu cầu cấp quyền cho một ứng dụng khác.
Thuộc tính này được đặt ở dạng tham chiếu đến tài nguyên chuỗi. Không giống như thuộc tính
label
, thuộc tính này không được là một chuỗi thô. android:icon
- Tham chiếu đến tài nguyên có thể vẽ cho biểu tượng mà đại diện cho quyền.
android:label
- Tên quyền dễ đọc đối với người dùng.
Để thuận tiện, bạn có thể đặt nhãn trực tiếp dưới dạng chuỗi thô trong khi phát triển ứng dụng. Tuy nhiên, khi ứng dụng sẵn sàng để xuất bản, hãy đặt nhãn này ở dạng tham chiếu đến một tài nguyên chuỗi, cho phép bản địa hoá nhãn này như các chuỗi khác trong giao diện người dùng.
android:name
- Là tên được dùng trong mã để nói đến quyền, chẳng hạn như trong phần tử
<uses-permission>
hoặc thuộc tínhpermission
của các thành phần ứng dụng.Lưu ý: Hệ thống không cho phép nhiều gói khai báo một quyền có cùng tên, trừ trường hợp tất cả các gói được ký bằng cùng một chứng chỉ. Nếu một gói khai báo quyền, hệ thống sẽ không cho phép người dùng cài đặt các gói khác có cùng tên quyền, trừ trường hợp các gói đó được ký bằng cùng một chứng chỉ với gói đầu tiên.
Vì lý do này, Google khuyên bạn nên đặt tiền tố cho quyền bằng tên gói của ứng dụng dùng cách đặt tên kiểu đảo ngược miền. Sau tiền tố này là
.permission.
, tiếp đến là nội dung mô tả về chức năng mà quyền đó biểu thị ở phần trên của SNAKE_CASE. Ví dụ:com.example.myapp.permission.ENGAGE_HYPERSPACE
.Làm theo đề xuất này sẽ giúp tránh xảy ra xung đột khi đặt tên và giúp xác định rõ ràng chủ sở hữu cũng như ý định của một quyền tuỳ chỉnh.
android:permissionGroup
- Chỉ định quyền này cho một nhóm. Giá trị của thuộc tính này là tên của nhóm và phải được khai báo bằng phần tử
<permission-group>
trong ứng dụng này hoặc một ứng dụng khác. Nếu bạn không đặt thuộc tính này thì quyền sẽ không thuộc về nhóm nào. android:protectionLevel
-
Biểu thị đặc điểm rủi ro tiềm ẩn trong quyền và cho biết quy trình mà hệ thống nên tuân theo khi xác định liệu có cần cấp quyền cho một ứng dụng yêu cầu quyền hay không.
Mỗi cấp độ bảo vệ bao gồm một loại quyền cơ sở và có số lượng cờ từ 0 trở lên. Ví dụ: cấp độ bảo vệ
"dangerous"
sẽ không có cờ. Ngược lại, cấp bảo vệ"signature|privileged"
là sự kết hợp của loại quyền cơ sở"signature"
và cờ"privileged"
.Bảng sau đây trình bày tất cả các loại quyền cơ sở. Để xem danh sách cờ, hãy xem phần
protectionLevel
.Giá trị Ý nghĩa "normal"
Giá trị mặc định. Quyền có mức độ rủi ro thấp hơn cho phép ứng dụng yêu cầu quyền này truy cập vào các tính năng riêng biệt ở cấp ứng dụng mà chỉ gây ra rủi ro ở mức tối thiểu đối với các ứng dụng, hệ thống hoặc người dùng khác. Hệ thống tự động cấp loại quyền này cho ứng dụng yêu cầu quyền tại thời điểm cài đặt mà không cần xin phép người dùng đồng ý, mặc dù người dùng luôn có thể xem qua các quyền này trước khi cài đặt. "dangerous"
Quyền có mức độ rủi ro cao hơn cho phép ứng dụng yêu cầu quyền này truy cập vào dữ liệu riêng tư của người dùng hoặc quyền kiểm soát thiết bị mà có thể ảnh hưởng tiêu cực đến người dùng. Vì loại quyền này có thể gây ra rủi ro tiềm ẩn nên hệ thống có thể không tự động cấp quyền đó cho ứng dụng yêu cầu. Ví dụ: bất kỳ quyền nguy hiểm nào mà ứng dụng yêu cầu có thể hiển thị cho người dùng và yêu cầu họ xác nhận trước khi tiếp tục, hoặc một số phương pháp khác có thể được thực hiện để tránh việc người dùng tự động cho phép ứng dụng yêu cầu truy cập. "signature"
Quyền mà hệ thống chỉ cấp khi ứng dụng yêu cầu được ký bằng cùng một chứng chỉ với ứng dụng đã khai báo quyền. Nếu các chứng chỉ khớp với nhau, hệ thống sẽ tự động cấp quyền mà không thông báo cho người dùng hoặc không yêu cầu sự chấp thuận rõ ràng của người dùng. "knownSigner"
Hệ thống chỉ cấp quyền khi ứng dụng yêu cầu được ký bằng một chứng chỉ được phép. Nếu chứng chỉ của ứng dụng yêu cầu có trong danh sách, thì hệ thống sẽ tự động cấp quyền mà không thông báo cho người dùng hoặc không yêu cầu sự chấp thuận rõ ràng của người dùng. "signatureOrSystem"
Từ đồng nghĩa cũ của
"signature|privileged"
. Không được dùng trong API cấp 23 nữa.Quyền mà hệ thống chỉ cấp cho ứng dụng nằm trong một thư mục chuyên dụng trong ảnh hệ thống Android hoặc được ký bằng cùng một chứng chỉ với ứng dụng đã khai báo quyền. Hãy tránh sử dụng tuỳ chọn này, vì cấp độ bảo vệ
"signature"
là đủ cho hầu hết các nhu cầu và hoạt động bất kể nơi cài đặt ứng dụng.Quyền "
"signatureOrSystem"
" được dùng cho một số trường hợp đặc biệt trong đó nhiều nhà cung cấp có các ứng dụng được tích hợp vào ảnh hệ thống và cần chia sẻ một số tính năng cụ thể một cách rõ ràng vì các nhà cung cấp đó được tạo cùng nhau.
- ra mắt từ:
- API cấp 1
- xem thêm:
<uses-permission>
<permission-tree>
<permission-group>
<quyền>
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# <permission\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cpermission android:description=\"string resource\"\n android:icon=\"drawable resource\"\n android:label=\"string resource\"\n android:name=\"string\"\n android:permissionGroup=\"string\"\n android:protectionLevel=[\"normal\" | \"dangerous\" |\n \"signature\" | ...] /\u003e\n ```\n\ncontained in:\n: [\u003cmanifest\u003e](/guide/topics/manifest/manifest-element)\n\ndescription:\n: Declares a security permission used to\n limit access to specific components or features of this or other applications.\n For more information about how permissions work, see the [Permissions](/guide/topics/manifest/manifest-intro#perms) section in the app manifest overview and [Security tips](/guide/topics/security/security).\n\nattributes:\n:\n\n `android:description`\n\n : A user-readable description of the permission that is longer and more informative than the label. It might display, for example, to explain the permission to the user when the user is asked to grant the permission to another application.\u003cbr /\u003e\n\n\n This attribute is set as a reference to a string resource.\n Unlike the `label` attribute, it can't be a raw string.\n\n `android:icon`\n : A reference to a drawable resource for an icon that represents the\n permission.\n\n `android:label`\n\n : A user-readable name for the permission.\u003cbr /\u003e\n\n\n As a convenience, the label can be directly set\n as a raw string while you're developing the application. However,\n when the application is ready to publish, set it as a\n reference to a string resource, so that it can be localized like other\n strings in the user interface.\n\n `android:name`\n : The name to be used in\n code to refer to the permission, such as in a\n [\u003cuses-permission\u003e](/guide/topics/manifest/uses-permission-element) element or the\n `permission` attributes of application components.\n\n\n **Note:** The system doesn't let multiple packages declare\n a permission with the same name unless all the packages are signed with the\n same certificate. If a package declares a permission, the system doesn't permit\n the user to install other packages with the same permission name, unless\n those packages are signed with the same certificate as the first package.\n\n For this reason, Google recommends prefixing permissions with the app's package name,\n using reverse-domain-style naming.\n Follow this prefix with `.permission.` and then a description of the\n capability that the permission represents in upper SNAKE_CASE. For example:\n `com.example.myapp.permission.ENGAGE_HYPERSPACE`.\n\n Following this recommendation avoids naming collisions and helps clearly identify the owner\n and intention of a custom permission.\n\n `android:permissionGroup`\n : Assigns this permission to a group. The value of this attribute is\n the name of the group, which is declared with the\n [\u003cpermission-group\u003e](/guide/topics/manifest/permission-group-element) element in this\n or another application. If this attribute isn't set, the permission\n doesn't belong to a group.\n\n `android:protectionLevel`\n\n :\n Characterizes the potential risk implied in the permission and\n indicates the procedure for the system to follow when determining\n whether to grant the permission to an application requesting it.\n\n\n Each protection level consists of a base permission type and zero or more\n flags. For example, the `\"dangerous\"` protection level has no\n flags. In contrast, the protection level `\"signature|privileged\"`\n is a combination of the `\"signature\"` base permission type and the\n `\"privileged\"` flag.\n\n\n The following table shows all base permission types. For a list of flags, see\n [protectionLevel](/reference/android/R.attr#protectionLevel).\n\n | Value | Meaning |\n |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | `\"normal\"` | The default value. A lower-risk permission that gives requesting applications access to isolated application-level features with minimal risk to other applications, the system, or the user. The system automatically grants this type of permission to a requesting application at installation, without asking for the user's explicit approval, though the user always has the option to review these permissions before installing. |\n | `\"dangerous\"` | A higher-risk permission that gives a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system might not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application might be displayed to the user and require confirmation before proceeding, or some other approach might be taken to avoid the user automatically granting the use of such facilities. |\n | `\"signature\"` | A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval. |\n | `\"knownSigner\"` | A permission that the system grants only if the requesting application is signed with [an allowed certificate](/guide/topics/permissions/defining#grant-signature-permissions). If the requester's certificate is listed, the system automatically grants the permission without notifying the user or asking for the user's explicit approval. |\n | `\"signatureOrSystem\"` | *Old synonym for `\"signature|privileged\"`. Deprecated in API level 23.* A permission that the system grants only to applications that are in a dedicated folder on the Android system image *or* that are signed with the same certificate as the application that declared the permission. Avoid using this option, as the `\"signature\"` protection level is sufficient for most needs and works regardless of where apps are installed. The `\"signatureOrSystem\"` permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together. |\n\nintroduced in:\n: API level 1\n\nsee also:\n: [\u003cuses-permission\u003e](/guide/topics/manifest/uses-permission-element)\n\n [\u003cpermission-tree\u003e](/guide/topics/manifest/permission-tree-element)\n\n [\u003cpermission-group\u003e](/guide/topics/manifest/permission-group-element)"]]