Infinite loop occurs when displaying SettingsDialog with onPermissionsDenied
Nunocky opened this issue · 1 comments
Nunocky commented
Basic Information
Device type: Emulator (Pixel4 API 29)
OS version: Android 10
EasyPermissions version: 1.0.0
Question
Sorry for the series of questions.
I'm trying to create a function like "Open app settings when some permissions are permanently denied", but it doesn't work.
In the onPermissionsDenied callback, I evaluate somePermissionPermanentlyDenied() and open the SettingsDialog from there, but the Fragment from which the call is made is being called infinitely.
Is it wrong to try to open the SettingsDialog at this location? If so, how do I open the SettingsDialog correctly?
Code and logs
I have uploaded the source code to github.
https://github.com/Nunocky/EasyPermissionsStudy
override fun onResume() {
super.onResume()
checkPermissions()
}
// -----------------------------------------------
// permissions issue
// -----------------------------------------------
private val requiredPermissions = listOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
)
private fun checkPermissions() {
if (!EasyPermissions.hasPermissions(
requireContext(),
*(requiredPermissions.toTypedArray())
)
) {
// Do not have permissions, request them now
EasyPermissions.requestPermissions(
host = this,
rationale = "permissions required",
requestCode = REQUEST_PERMISSIONS,
perms = requiredPermissions.toTypedArray()
)
}
}
override fun onPermissionsDenied(requestCode: Int, perms: List<String>) {
if (EasyPermissions.somePermissionPermanentlyDenied(this, requiredPermissions)) {
toast("somePermissionPermanentlyDenied")
SettingsDialog.Builder(requireContext())
.build()
.show()
}
}
jjerome00 commented
you need to remove your permission check from onResume()