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:
- 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.
- 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.
I have a similar issue. OS.request_permissions()
works and I see the logs in LogCat stating that I granted the permission requests, but my on_request_permissions_result
is never call. Did you have to bind that signal handler somehow? I’m wondering if I’m missing some sort of signal handler registration in my gdscript.
Historically (and probably still, but it’s been a while for me) on mobile OSs you only get to ask for a permission once, and if the user says “no” then that’s the end of it; if you ask again, the user sees nothing and you get told the user said “no”.
Unfortunately, this is one of those cases where bad actors (primarily involving scams, user tracking and adware) have ruined it for the rest of us. If you could request permission again even if the user said “no”, we’d very quickly be in a world where “Best Practices” in freemium apps would be to nag the user until they gave in or hit “yes” by accident, probably paired with dark patterns about when to ask.
If you want to save, and get_granted_permissions()
says “no”, all you can really do is put up some text saying something like:
Saving requires access to external storage, which has not been enabled. If you wish to use this functionality, go to Settings->[…]
On Android I believe you can make a deep link to the appropriate location in the settings that jumps the user directly where they need to be. IIRC on iOS you aren’t allowed to deep link, but you can at least bring the settings app up.
1 Like