How to aks permission only when relevant

Godot Version

Godot 4.2

Question

I’m making an Android App with Godot 4.2.
In it there’s a functionality that saves and writes files in the phone’s external storage. That much is already working.
However, Android’s policies only allow the App to access files created by the current installation of the app. To access all the files I have to ask the permission to “Manage External Storage”. If I select this permission on the export page, as soon as the App is opened the user is prompted to allow it, and everything works as it should it the user allow it.
The problem is two-fold:

  1. I don’t want to ask permission as soon as the app is opened. I want to ask only when/if relevant, i.e. if the user tries to use the file explorer functionality. This funcionality is not necessary for the main use of the app, and the user may never even have to use it. So I don’t want to bother the user with an invasive permission upfront.
  2. If the user denies the permission, how do I ask for it again when it’s actually needed?
    I used OS.get_granted_permissions() to verify if the permission was granted and either way a call to OS.request_permission() doesn’t do anything.

Any help is appreciated. Thanks

A couple hundred tests later and I’m back.
OS.request_permission() does work, but not with all the checkable permissions from the export preset (at least on the phone that I’m testing on).
My actual problem is the signal get_tree().on_request_permissions_result, which is supposed to be used as a way to wait for the user’s response and is not reliable at all. Either is returns immediately saying the user denied the request or it doesn’t return anything and just holds the rest of the code.