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

API 30 Android 11: Requesting background location permission #281

@dds861

Description

@dds861

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions