Permissions Dialog not showing in Android 11

Viewed 4605

In my app I need access to 4 permissions (which are already declared in the manifest)

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

In my code I check If I already have permissions, and if NOT:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                requestPermissions(
                    arrayOf(
                          Manifest.permission.ACCESS_FINE_LOCATION,
                          Manifest.permission.ACCESS_COARSE_LOCATION,
                          Manifest.permission.ACCESS_BACKGROUND_LOCATION), 1)
            } else {
                ActivityCompat.requestPermissions(this, arrayOf(
                  Manifest.permission.ACCESS_FINE_LOCATION,
                  Manifest.permission.ACCESS_COARSE_LOCATION,
                  Manifest.permission.ACCESS_BACKGROUND_LOCATION), 1)
            }

This code works in my emulator, which has a 29 API. But on my own device, the permissions popup won't show. Do you guys know why?

3 Answers

Any Android apps targeting API 30 are now no longer allowed to ask for BACKGROUND_PERMISSION at the same time as regular location permission. You have to split it into 2 seperate asks:

  1. Ask for regular foreground location permission, once granted,
  2. Ask for BACKGROUND_LOCATION permission on a new ask

Android 11

Android 11, if the user taps Deny for a specific permission more than once during your app's lifetime of installation on a device, the user doesn't see the system permissions dialog if your app requests that permission again

The system resets only runtime permissions, which are the permissions that display a runtime prompt to the user when requested.

More details refer this Permissions

Starting in Android 11, if the user taps Deny for specific permission more than once during your app's lifetime of installation on a device, the user doesn't see the system permissions dialog if your app requests that permission again. The user's action implies "don't ask again." On previous versions, users would see the system permissions dialog each time your app requested a permission, unless the user had previously selected a "don't ask again" checkbox or option. This behavior change in Android 11 discourages repeated requests for permissions that users have chosen to deny.

Reference Here.

Related