Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

API 30 Android 11: Requesting background location permission #281

Open
dds861 opened this issue Jun 16, 2021 · 0 comments
Open

API 30 Android 11: Requesting background location permission #281

dds861 opened this issue Jun 16, 2021 · 0 comments

Comments

@dds861
Copy link

dds861 commented Jun 16, 2021

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(...))

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants