When a user denies permissions and selects 'never ask again', you can use .onForwardToSettings to guide them to the app settings. This should be chained before the .request() method.
Use scope.showForwardToSettingsDialog(deniedList, message, positiveButtonText, negativeButtonText):
- If the user clicks the positive button, PermissionX will open the app's settings page. When the user returns to the app, PermissionX will automatically re-request the necessary permissions.
- Parameters are similar to
showRequestReasonDialog.
PermissionX.init(activity)
.permissions(Manifest.permission.READ_CONTACTS, Manifest.permission.CAMERA, Manifest.permission.CALL_PHONE)
.onExplainRequestReason { scope, deniedList ->
scope.showRequestReasonDialog(deniedList, "Core fundamental are based on these permissions", "OK", "Cancel")
}
.onForwardToSettings { scope, deniedList ->
scope.showForwardToSettingsDialog(deniedList, "You need to allow necessary permissions in Settings manually", "OK", "Cancel")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(this, "All permissions are granted", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(this, "These permissions are denied: $deniedList", Toast.LENGTH_LONG).show()
}
}