fondesa/kpermissions

listenerOf is null when requesting implicit permissions

cirnoftw opened this issue · 2 comments

Description

The attachListener method is called with an array of 3 string permission names as a key, but when an explicit permission is granted (such as Manifest.permission.ACCESS_FINE_LOCATION), method managePermissionsResult is called with an array of only one permission name, so the method listenerOf doesn't match the existing listener and returns null, so the listener is not called.


KPermissions version: 3.1.3

API level: 30

How to reproduce it:
Request multiple permissions, including some permissions which may be implicit, such as:

Manifest.permission.ACCESS_FINE_LOCATION
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN

Sample code:

    fun checkCallback(activity: Activity?, callback: (Boolean) -> Unit) {
        val bluetoothRequest = (activity as? FragmentActivity)?.permissionsBuilder(
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.BLUETOOTH,
            Manifest.permission.BLUETOOTH_ADMIN
        )?.build()
        bluetoothRequest?.addListener { status -> callback(status.allGranted()) }
        bluetoothRequest?.send()
    }

Nice catch, thanks for reporting it.

Anyway, in the next version of the library I'm currently working on, the listener won't be retrieved using the permissions returned in onPermissionsResult(), but it will retrieved using the permissions listed in permissionsBuilder(...) so this issue will be solved.

I'm leaving this issue open until I won't release the next version.

Published the version 3.2.0 containing the fix.

Feel free to re-open this if the issue is still present.