<uses-permission>
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
注意: 在某些情況下,您要求的權限
使用 <uses-permission>
可能會影響 Google Play 篩選
應用程式。如果要求取得硬體相關權限,例如
CAMERA
,Google Play 會假設您的
應用程式需要基礎硬體功能,並篩選應用程式
凡是不支援這項功能的裝置
如要控制篩選功能,請一律在 <uses-feature>
元素中明確宣告硬體功能,不要仰賴 Google Play「探索」<uses-permission>
元素的需求。然後,如要針對特定功能停用篩選,您可以在 <uses-feature>
宣告中加入 android:required="false"
屬性。
如需隱含硬體功能的權限清單,請參閱 <uses-feature>
元素的說明文件。
- 語法:
<uses-permission android:name="string"
android:maxSdkVersion="integer" />
- 包含於:
<manifest>
- 說明:
- 指定使用者必須授予的系統權限
能正常運作。當使用者在
應用程式安裝在搭載 Android 5.1 以下版本的裝置上,或在執行 Android 6.0 以上版本的裝置上執行。
如要進一步瞭解權限,請參閱
權限
應用程式資訊清單總覽中的專區,以及
「Android 中的權限」指南。
您可以在以下網址查看基礎平台定義的權限清單:
android.Manifest.permission
。
- 屬性:
android:name
- 權限的名稱。通常是由
使用
<permission>
執行應用程式
元素、其他應用程式定義的權限
標準系統權限,例如
"android.permission.CAMERA"
或 "android.permission.READ_CONTACTS"
。如這些範例所示
權限名稱通常以套件名稱做為前置字元。
android:maxSdkVersion
- 應用程式獲得此權限的最高 API 級別。
如果一開始不再需要應用程式所需的權限,設定這個屬性就能派上用場
指定 API 級別
舉例來說,從 Android 4.4 (API 級別 19) 開始,您的應用程式已不再需要這個平台
要求 WRITE_EXTERNAL_STORAGE
寫入其外部儲存空間上的應用程式特定目錄
提供者:getExternalFilesDir()
。
不過
API 級別 18 以下則「需要」權限。因此,您可以宣告
只有 API 級別 18 以下需要的權限,以及下列宣告:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
這樣一來,從 API 級別 19 開始,系統就不會再將
WRITE_EXTERNAL_STORAGE
權限。
已在 API 級別 19 中新增。
- 導入版本:
- API 級別 1
- 另請參閱:
-
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],null,["# <uses-permission\u003e\n\n**Note:** In some cases, the permissions that you request\nthrough `\u003cuses-permission\u003e` can affect how Google Play filters your\napplication. If you request a hardware-related permission, such as\n`CAMERA`, Google Play assumes that your\napplication requires the underlying hardware feature and filters the application\nfrom devices that don't offer it.\n\nTo control filtering, always explicitly declare\nhardware features in `\u003cuses-feature\u003e` elements, rather than\nrelying on Google Play to \"discover\" the requirements in\n`\u003cuses-permission\u003e` elements. Then, if you want to disable\nfiltering for a particular feature, you can add a\n`android:required=\"false\"` attribute to the\n`\u003cuses-feature\u003e` declaration.\n\nFor a list of permissions that imply\nhardware features, see the documentation for the [`\u003cuses-feature\u003e`](/guide/topics/manifest/uses-feature-element#permissions-features) element.\n\nsyntax:\n:\n\n ```xml\n \u003cuses-permission android:name=\"string\"\n android:maxSdkVersion=\"integer\" /\u003e\n ```\n\ncontained in:\n: [\u003cmanifest\u003e](/guide/topics/manifest/manifest-element)\n\ndescription:\n\n: Specifies a system permission that the user must grant for the app to operate correctly. The user grants permissions when the application installs, on devices running Android 5.1 and lower, or while the app runs, on devices running Android 6.0 and higher.\u003cbr /\u003e\n\n\n For more information on permissions, see the\n [Permissions](/guide/topics/manifest/manifest-intro#perms)\n section in the app manifest overview and the\n [Permissions on Android](/guide/topics/permissions) guide.\n A list of permissions defined by the base platform is at\n [android.Manifest.permission](/reference/android/Manifest.permission).\n\nattributes:\n:\n\n `android:name`\n : The name of the permission. It can be a permission defined by the\n application with the [\u003cpermission\u003e](/guide/topics/manifest/permission-element)\n element, a permission defined by another application, or one of the\n standard system permissions, such as\n [\"android.permission.CAMERA\"](/reference/android/Manifest.permission#CAMERA)\n or [\"android.permission.READ_CONTACTS\"](/reference/android/Manifest.permission#READ_CONTACTS). As these examples show,\n a permission name typically includes the package name as a prefix.\n\n `android:maxSdkVersion`\n\n : The highest API level at which this permission is granted to your app. Setting this attribute is useful if the permission your app requires is no longer needed beginning at a certain API level.\u003cbr /\u003e\n\n For example, beginning with Android 4.4 (API level 19) it's no longer necessary for your app\n to request the [WRITE_EXTERNAL_STORAGE](/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE)\n permission to write to its own application-specific directories on external storage, which are\n provided by [getExternalFilesDir()](/reference/android/content/Context#getExternalFilesDir(java.lang.String)).\n\n However,\n the permission *is required* for API level 18 and lower. So you can declare that this\n permission is needed only up to API level 18 with a declaration like the following: \n\n ```xml\n \u003cuses-permission\n android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"\n android:maxSdkVersion=\"18\" /\u003e\n ```\n\n This way, beginning with API level 19, the system no longer grants your app the\n `WRITE_EXTERNAL_STORAGE` permission.\n\n Added in API level 19.\n\nintroduced in:\n: API level 1\n\nsee also:\n:\n - [\u003cpermission\u003e](/guide/topics/manifest/permission-element)\n - [`\u003cuses-permission-sdk-23\u003e`](/guide/topics/manifest/uses-permission-sdk-23-element)\n - [\u003cuses-feature\u003e](/guide/topics/manifest/uses-feature-element)"]]