Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permissions Dialog not showing in Android 11

Tags:

android

kotlin

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?

like image 609
André Nogueira Avatar asked Nov 24 '25 11:11

André Nogueira


2 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
like image 131
Geordie Wicks Avatar answered Nov 27 '25 01:11

Geordie Wicks


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

like image 37
sasikumar Avatar answered Nov 27 '25 01:11

sasikumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!