1. ホーム
  2. Android

AndroidManifestのuses-permissionの設定

2022-02-18 21:26:50
<パス

説明

uses-permission は、AndroidManifest.xml で最も一般的な設定の 1 つで、アプリを実行するために必要なアクセス許可を宣言するために使用されます。ここで宣言されたパーミッションは、アプリがインストールされるときにユーザーに警告を発し、ユーザーはインストールに同意するか拒否するかを選択することができます。Android 6.0以前では、ユーザーがインストールに同意すると、AndroidManifest.xmlで宣言されたすべてのパーミッションの使用に同意することになりますが、Android 6.0以降では、アプリケーションのパーミッションは、NormalパーミッションとDangerousパーミッションに分類されるようになっています。AndroidManifest.xmlで宣言されているNormal permissionsについては、従来通り、ユーザーがアプリケーションのインストールに同意すれば、これらの権限が付与されます。AndroidManifest.xml で宣言されている Dangerous permissions については、アプリケーションがこれらのパーミッションを使用する必要があり、ユーザーがインストールに同意して、自動的にこれらのパーミッションが付与されないことを意味するだけで、アプリケーションが実行時にこれらのパーミッションを使用する場合、コード内でパーミッションを申請する必要があり、ユーザーが同意した場合にのみ付与されます。また、ユーザーが同意した後、システム設定でいつでもこのようなパーミッションの認可を取り消すことができます。

構文

Affiliate Nodes
Attributes
android:name

The name of the permission that needs to be used, either one that comes with the system or a custom one. android provides more than 100 permissions that can be accessed via the https://developer.android.com/reference/android/Manifest.permission.html to see the names and meanings of these permissions. Most of these permission names are prefixed with android.permission. but a small number are prefixed with com.android. and need to be distinguished. android:maxSdkVersion
Indicates the highest system API Levle that requires this permission, for example, setting android:maxSdkVersion to 21 means that this permission is only required for systems at API Level 21 (Android 5.0) and below. This permission is not required for systems above API Level 21. One of the more common permissions used in conjunction with the android:maxSdkVersion property is android.permission.WRITE_EXTERNAL_STORAGE. When an app is installed on the system, Android allocates an external storage space for it to use (in the app via getExternalFilesDir() and getExternalCacheDir()), in the system before Android 4.4 (API level 19), to write files to this storage, you need to get the android.permission.WRITE_EXTERNAL_STORAGE permission. STORAGE permission, but from Android 4.4 onwards, you don't need any permission to read or write to this part of storage anymore. So if you don't need to read external storage files other than this part of storage, you can declare this permission in AndroidManifest.xml like this.
Notes. 

1. there is no configuration property like android:minSdkVersion in uses-permission.
2. In the same AndroidManifest.xml, duplicate uses-permission configurations are allowed, that is, configurations with the same android:name and android:maxSdkVersion are allowed. But do not allow the configuration with the same android:name and different android:maxSdkVersion.
For example, the following configuration is allowed. The following configuration is not allowed Impact on app marketplace software distribution Some of the uses-permission permission declarations affect the app marketplace's software distribution policies. For example, an app declares the CAMERA permission in uses-permission, which means that the app needs to use the camera to work properly. If there is no camera on a device, then when a user searches or browses for an app on that device via Google Play, the app will not be found. If an app needs to use the camera, but it is not required and most features work without it, then you need to add the <uses-feature> declaration along with the CAMERA permission in AndroidManifest.xml.
For Google Play's filtering policy see https://developer.android.com/google/play/filters.html
Impact on app market review The permissions declared by uses-permission affect whether the app passes the review. The review criteria of different marketplaces are different. Generally, domestic marketplaces are more lenient in their review of app permissions, such as reading and modifying contacts, sending and receiving text messages, getting GPS location information, and enabling camera. Google Play, on the other hand, is very strict in its review of app permissions, and any permission application that is beyond the scope of the app's own function will not pass. If you really need a certain permission, you can submit a statement that you must use the permission, for example, a browser needs to enable the camera, an input method needs to read the address book, such permission applications must have a good and reasonable reason to be reviewed and approved. And applications containing system-level permissions such as SYSTEM_ALERT_WINDOW, READ_LOGS are basically impossible to pass Google Play's review. So the domestic app needs to remove all unnecessary permission declarations and corresponding call codes from AndroidManifest before publishing to Google Play. Reference links https://developer.android.com/guide/topics/manifest/manifest-intro.html#perms https://developer.android.com/guide/topics/manifest/uses-permission-element.html https://developer.android.com/guide/topics/security/permissions.html https://developer.android.com/training/permissions/best-practices.html