Karumi / Dexter

Android library that simplifies the process of requesting permissions at runtime.
http://karumi.com
Apache License 2.0
5.23k stars 671 forks source link

Application stuck when requesting ACCESS_BACKGROUND_LOCATION #240

Closed choryuidentify closed 4 years ago

choryuidentify commented 4 years ago

Expected behaviour

Show permission is granted or not granted

Actual behaviour

Stuck on there tested on Android Q Emulator

Steps to reproduce

Permission -> Location -> Choose 'Allow only while using app' then, write code

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        Dexter.withActivity(this)
                .withPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
                .withListener(object : PermissionListener{
                    override fun onPermissionRationaleShouldBeShown(permission: PermissionRequest?, token: PermissionToken?) {
                        Log.d("debug", "onPermissionRationaleShouldBeShown")
                    }

                    override fun onPermissionDenied(response: PermissionDeniedResponse?) {
                        Log.d("debug", "denied")
                    }

                    override fun onPermissionGranted(response: PermissionGrantedResponse?) {
                        Log.d("debug", "granted")
                    }
                }).check()
    }

and run, choose 'Keep while-in-use access' or 'Keep and don't ask again', It stuck. If choose 'Allow all time', It stuck too but restart app, it will execute onPermissionGranted block

Version of the library

6.0.0

AlexDundar commented 4 years ago

I have the same problem. Is there any solution?

pedrovgs commented 4 years ago

Hi @choryuidentify @AlexDundar I've been testing the issue you reported and it's not related to Dexter but the way you ask for the permission. When using the background location permission you have to request the fine location or coarse location permission too. However, your code is only requesting the background ones. If you use this code you'll see how the app is working now:

Dexter.withActivity(this)
            .withPermissions(Manifest.permission.ACCESS_BACKGROUND_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
            .withListener(object : MultiplePermissionsListener {
                override fun onPermissionsChecked(report: MultiplePermissionsReport?) {

                }

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

                }

            }).check()

Remember to declare these permissions in the manifest.

Here you can find two useful resources related to this topic:

Screenshot 2019-11-08 at 12 49 46

Screenshot 2019-11-08 at 12 51 08

I hope this answers your question. I'm closing the issue for now. However, feel free to open it again if you think Dexter is not able to handle this permission properly.

dds861 commented 3 years ago

on api 30 it doesn't work. created an issue, waiting for someone to comment ...

PavelMostovoy commented 3 years ago

it works on API 29, but doesn't work on API 30