Android 11 gives users the ability to specify more granular permissions for location, microphone, and camera. This version of Android also updates the permissions model for reading information related to phone numbers.
We're interested in hearing your feedback! Please take this short survey to let us know how you're using the feature. In particular, tell us about use cases impacted by this feature.
In Android 11, whenever your app requests a permission related to location, microphone, or camera, the user-facing permissions dialog contains an option called Only this time. If the user selects this option in the dialog, your app is granted a temporary one-time permission.
Your app can then access the related data for a period of time that depends on your app's behavior and the user's actions:
- While your app's activity is visible, your app can access the data.
- If the user brings your app to the background, your app can continue to access the data for a short period of time.
- If you launch a foreground service while the activity is visible, and the user then moves your app to the background, your app can continue to access the data until that foreground service stops.
- If the user revokes the one-time permission, such as in system settings, your app cannot access the data, regardless of whether you launched a foreground service. As with any permission, if the user revokes your app's one-time permission, your app's process terminates.
Note: If your app already follows best practices related to permissions, you don't need to change your app to support one-time permissions. In particular, make sure you always check that your app has a permission before trying to access information that's guarded by that permission, and complete the following process if your app is requesting the permission for the first time, or if the user has revoked the permission:
shouldShowRequestPermissionRationale(). If this method returns true, show a UI element in your app that explains to the user why your app needs the permission.
- Request the permission.
Dialog shown when requesting permission again
When the user next opens your app and your app then requests a permission related to location, microphone, or camera again, the user is prompted again. Table 1 shows several examples of the dialog that the user might see:
|Target SDK version||Type of permission requested||Dialog that user sees|
|Android 10 or higher||
|Android 10 or lower||All available location permissions simultaneously||Figure 3|
Permission dialog visibility
Android 11 discourages repeated requests for permissions in a specific permission group. If the user taps Deny twice for a specific permission during your app's lifetime of installation on a device, this action implies "don't ask again" for the corresponding permission group.
The system also defines behavior for responding to actions that emulate a tap of the Deny option:
- If the user presses the back button to dismiss the permission dialog, this doesn't count as a "deny" action.
- If the user is taken to system settings from your app using
requestPermissions()and then presses the back button, this does count as a "deny" action.
Android 11 changes the phone-related permission that your app uses when reading phone numbers.
If your app targets Android 11 and needs to access the phone
number APIs shown in the following list, you must request the
permission, instead of the
getLine1Number()method in both the
TelephonyManagerclass and the
- The unsupported
getMsisdn()method in the
If your app declares
READ_PHONE_STATE to call methods other than the ones in
the previous list, you can continue to request
READ_PHONE_STATE across all
Android versions. If you use the
READ_PHONE_STATE permission only for the
methods in the previous list, however, update your manifest file as follows:
- Change your declaration of
READ_PHONE_STATEso that your app uses the permission only on Android 10 (API level 29) and lower.
- Add the
The following manifest declaration snippet demonstrates this process:
<manifest> <!-- Grants the READ_PHONE_STATE permission only on devices that run Android 10 (API level 29) and lower. --> <uses-permission android:name="READ_PHONE_STATE" android:maxSdkVersion="29" /> <uses-permission android:name="READ_PHONE_NUMBERS" /> </manifest>