- ไวยากรณ์:
<permission android:description="string resource" android:icon="drawable resource" android:label="string resource" android:name="string" android:permissionGroup="string" android:protectionLevel=["normal" | "dangerous" | "signature" | ...] />
- ที่อยู่ใน:
<manifest>
- description:
- ประกาศสิทธิ์ความปลอดภัยที่ใช้เพื่อ จำกัดการเข้าถึงคอมโพเนนต์หรือฟีเจอร์เฉพาะของแอปพลิเคชันนี้หรือแอปพลิเคชันอื่น สำหรับข้อมูลเพิ่มเติมเกี่ยวกับวิธีการทำงานของสิทธิ์ ให้ดูที่ส่วนสิทธิ์ในภาพรวมไฟล์ Manifest ของแอปและเคล็ดลับความปลอดภัย
- ดังนี้
android:description
- คำอธิบายสิทธิ์ที่ผู้ใช้อ่านได้ ซึ่งมีความยาวและมากกว่า
ที่มีประโยชน์มากกว่าป้ายกำกับ เช่น ข้อมูลนี้อาจแสดงเพื่ออธิบาย
สิทธิ์ของผู้ใช้เมื่อมีการสอบถามผู้ใช้
เพื่อให้สิทธิ์แก่แอปพลิเคชันอื่น
แอตทริบิวต์นี้ตั้งเป็นการอ้างอิงทรัพยากรสตริง แอตทริบิวต์นี้แตกต่างจากแอตทริบิวต์
label
ตรงที่จะเป็นสตริงดิบไม่ได้ android:icon
- การอ้างอิงทรัพยากรที่ถอนออกได้สำหรับไอคอนที่แสดงถึง สิทธิ์
android:label
- ชื่อสิทธิ์ที่ผู้ใช้อ่านได้
คุณสามารถกำหนดป้ายกำกับโดยตรงเพื่อความสะดวก เป็นสตริงดิบในขณะที่คุณกำลังพัฒนาแอปพลิเคชัน อย่างไรก็ตาม เมื่อแอปพลิเคชันพร้อมที่จะเผยแพร่ ให้กำหนด การอ้างอิงไปยังทรัพยากรสตริง เพื่อให้ระบบแปลได้อย่างอิสระ สตริงในอินเทอร์เฟซผู้ใช้
android:name
- ชื่อที่จะใช้
เพื่ออ้างถึงสิทธิ์ เช่น
<uses-permission>
หรือ แอตทริบิวต์permission
ของคอมโพเนนต์แอปพลิเคชันหมายเหตุ: ระบบไม่อนุญาตให้ประกาศแพ็กเกจหลายรายการ สิทธิ์ที่มีชื่อเดียวกัน เว้นแต่ว่าแพ็กเกจทั้งหมดจะมีการลงชื่อด้วย ใบรับรองเดียวกัน หากแพ็กเกจประกาศสิทธิ์ ระบบจะไม่อนุญาต ให้ผู้ใช้ติดตั้งแพ็กเกจอื่นๆ ที่มีชื่อสิทธิ์เหมือนกัน ยกเว้นในกรณีที่ แพ็กเกจเหล่านั้นลงชื่อด้วยใบรับรองเดียวกันกับแพ็กเกจแรก
ด้วยเหตุนี้ Google ขอแนะนำให้ใช้คำนำหน้าชื่อแพ็กเกจของแอป โดยใช้การตั้งชื่อแบบย้อนกลับ ติดตามคำนำหน้านี้ด้วย
.permission.
ตามด้วยคำอธิบายของ ความสามารถที่สิทธิ์แสดงในรูปแบบ SNAKE_CASE ด้านบน ดังตัวอย่างต่อไปนี้com.example.myapp.permission.ENGAGE_HYPERSPACE
การทำตามคำแนะนำนี้จะหลีกเลี่ยงการตั้งชื่อชนกันและช่วยระบุเจ้าของอย่างชัดเจน และเจตนาของสิทธิ์ที่กำหนดเอง
android:permissionGroup
- มอบสิทธิ์นี้ให้กับกลุ่ม ค่าของแอตทริบิวต์นี้คือ
ชื่อกลุ่ม ซึ่งประกาศด้วย
<permission-group>
องค์ประกอบใน หรือแอปพลิเคชันอื่น หากไม่ได้ตั้งค่าแอตทริบิวต์นี้ไว้สิทธิ์ ไม่ได้อยู่ในกลุ่ม android:protectionLevel
-
อธิบายลักษณะของความเสี่ยงที่อาจเกิดขึ้นในการอนุญาตและ ระบุกระบวนการให้ระบบปฏิบัติตามเมื่อพิจารณา จะให้สิทธิ์แอปพลิเคชันที่ขอการอนุญาตหรือไม่
ระดับการป้องกันแต่ละระดับประกอบด้วยประเภทสิทธิ์พื้นฐาน 1 รายการหรือมากกว่านั้น ตัวอย่างเช่น ระดับการป้องกัน
"dangerous"
จะไม่มี ในทางกลับกัน ระดับการป้องกัน"signature|privileged"
เป็นชุดค่าผสมของประเภทสิทธิ์พื้นฐาน"signature"
และ แฟล็ก"privileged"
ตารางต่อไปนี้แสดงประเภทสิทธิ์พื้นฐานทั้งหมด สำหรับรายการแฟล็ก โปรดดูที่
protectionLevel
ค่า ความหมาย "normal"
ค่าเริ่มต้น สิทธิ์ที่มีความเสี่ยงต่ำกว่าซึ่งทำให้มีคำขอ เข้าถึงคุณลักษณะระดับแอปพลิเคชันแบบแยกด้วย ความเสี่ยงต่ำต่อแอปพลิเคชัน ระบบ หรือผู้ใช้ ระบบจะให้สิทธิ์ประเภทนี้โดยอัตโนมัติ อนุญาตสำหรับแอปพลิเคชันที่ขอเมื่อติดตั้ง โดย ที่ได้รับการอนุมัติที่ชัดเจนจากผู้ใช้ แต่ถึงกระนั้น มีตัวเลือกในการตรวจสอบสิทธิ์เหล่านี้ก่อนการติดตั้ง "dangerous"
สิทธิ์ที่มีความเสี่ยงสูงซึ่งทำให้แอปพลิเคชันที่ขอ เข้าถึงข้อมูลผู้ใช้ส่วนตัวหรือควบคุมอุปกรณ์ที่สามารถ ส่งผลเสียต่อผู้ใช้ เนื่องจากสิทธิ์ประเภทนี้ อาจก่อให้เกิดความเสี่ยงได้ เนื่องจากระบบอาจไม่ได้ติดตาม ให้แอปพลิเคชันที่ขอ เช่น เนื้อหาที่เป็นอันตราย การอนุญาตที่ขอโดยแอปพลิเคชันอาจแสดงต่อ ผู้ใช้ และต้องมีการยืนยันก่อนที่จะดำเนินการต่อ หรือ เพื่อหลีกเลี่ยงการอนุญาตให้ผู้ใช้ การใช้งานสิ่งอำนวยความสะดวกดังกล่าว "signature"
สิทธิ์ที่ระบบกำหนดให้ก็ต่อเมื่อมีการส่งคำขอ ใบสมัครถูกลงชื่อด้วยใบรับรองเดียวกันกับใบสมัคร ที่ประกาศสิทธิ์นั้น ถ้าใบรับรองตรงกัน ระบบจะ ให้สิทธิ์โดยอัตโนมัติโดยไม่ต้องแจ้งให้ผู้ใช้ทราบ หรือ ที่รอการอนุมัติที่ชัดเจนจากผู้ใช้ "knownSigner"
สิทธิ์ที่ระบบกำหนดให้ก็ต่อเมื่อมีการส่งคำขอ แอปพลิเคชันมีการรับรองด้วย อนุญาต ใบรับรอง หากมีใบรับรองของผู้ขออยู่ในรายการ ระบบจะ ให้สิทธิ์โดยอัตโนมัติโดยไม่ต้องแจ้งให้ผู้ใช้ทราบ หรือ ที่รอการอนุมัติที่ชัดเจนจากผู้ใช้ "signatureOrSystem"
คำพ้องความหมายเดิมสำหรับ
"signature|privileged"
เลิกใช้งานใน API ระดับ 23สิทธิ์ที่ระบบกำหนดให้กับแอปพลิเคชันที่ ในโฟลเดอร์เฉพาะบนอิมเมจระบบ Android หรือที่ ลงชื่อด้วยใบรับรองเดียวกันกับแอปพลิเคชันที่ประกาศ สิทธิ์ หลีกเลี่ยงการใช้ตัวเลือกนี้ เนื่องจาก
"signature"
ระดับการป้องกันนั้นเพียงพอต่อความต้องการส่วนใหญ่และใช้งานได้ไม่ว่าจะ ของตำแหน่งที่ติดตั้งแอปสิทธิ์
"signatureOrSystem"
ใช้สำหรับข้อเสนอพิเศษบางอย่าง ในสถานการณ์ที่มีผู้ให้บริการหลายรายมีแอปพลิเคชันติดตั้งไว้ในระบบ และจำเป็นต้องแบ่งปันคุณลักษณะเฉพาะหนึ่งๆ อย่างชัดเจน สร้างสรรค์มาด้วยกัน
- เปิดตัวใน
- API ระดับ 1
- ดูเพิ่มเติม
<uses-permission>
<permission-tree>
<permission-group>
<permission>
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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)"]]