18

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?

André Nogueira
  • 3,363
  • 3
  • 10
  • 16
  • where you are calling dialog functions? – sasikumar Sep 08 '21 at 11:47
  • That method is called inside a method that is in onStart() – André Nogueira Sep 08 '21 at 11:48
  • 1
    You cannot request background location permission when foreground is not granted and requesting both at the same time is implicitly denied without showing system dialog. See [this question](https://stackoverflow.com/questions/64388343/activitycompat-requestpermissions-for-targetsdkversion-30-is-not-working/64388514#64388514) – Pawel Sep 08 '21 at 12:23

3 Answers3

24

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
Geordie Wicks
  • 1,065
  • 1
  • 11
  • 27
11

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

sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • 1
    I didnt tap deny because no dialog showed. I have reinstalled the app multiple Times and still no dialog – André Nogueira Sep 08 '21 at 11:58
  • make sure all instructions followed correctly – sasikumar Sep 08 '21 at 11:59
  • https://developer.android.com/training/permissions/requesting – sasikumar Sep 08 '21 at 12:00
  • This feature is explained very badly in developers guide for requesting permissions. That part of Android in developer guide is very complex and when this feature is not explained there, it makes developing permissions asking for new apps very confusing. I tried to find reason why me app is nor showing request dialog for days! Final logic for request asking was much simpler, than developer guide explains, but it is needed to guide end user to go Settings is some permissions is denied! – Reijo Korhonen May 15 '23 at 11:02
8

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.

Basil Rawa
  • 109
  • 1
  • 5