Karumi/Dexter

API 30 Android 11: Requesting background location permission

dds861 opened this issue · 0 comments

Expected behaviour

Show the same permission dialog as in API 29

Actual behaviour

Nothing happens. Permission dialog is being ignored

If your app targets Android 11 or higher, the system enforces this best practice. If you request a foreground location permission and the background location permission at the same time, the system ignores the request and doesn't grant your app either permission.
https://developer.android.com/about/versions/11/privacy/location#request-background-location-separately

https://developer.android.com/training/location/permissions#request-background-location

As i understand, i have to ask user for foreground location permission first, and then after giving permission i have to ask again for a background permission...

Steps to reproduce

in build.gradle change targetSdkVersion 30 and compileSdkVersion 30
use emulator API 30

just copy to mainActivity and call requestAccessFineLocation() from onCreate(...)

private fun requestAccessFineLocation() {
        Dexter.withContext(this)
            .withPermissions(createPermissionList1())
            .withListener(object : MultiplePermissionsListener {
                override fun onPermissionsChecked(report: MultiplePermissionsReport) {
                    Log.i("myApp", "onPermissionsChecked1 = " + report.areAllPermissionsGranted())

                }

                override fun onPermissionRationaleShouldBeShown(
                    permissions: MutableList<PermissionRequest>,
                    token: PermissionToken
                ) {

                    Log.i("myApp", "onPermissionRationaleShouldBeShown1")
                    token.continuePermissionRequest()
                }


            }).check()
    }
    private fun createPermissionList1(): MutableList<String> {
        val permissionList = mutableListOf(
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_BACKGROUND_LOCATION

        )
        return permissionList
    }

Version of the library

implementation 'com.karumi:dexter:6.2.2'
or
implementation 'com.karumi:dexter:4.2.0' (i changed withContext(...) to withActivity(...))