How to load files from user:// in android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lettucing

So, I’m trying to get an android version of my game working

On desktop, everything works like normal and files load
But on android, none of the external files work

If I do FileAccess.open(path, FileAccess.READ) on desktop, I get the file
But if I do it on android, I get null
This happens when trying to load from user:// and from res://
The user files exist in both the android and desktop user folders, and the android APK has storage permissions

This is the console output from desktop and android


Generally, saving / loading from user:// on Android should work as expected.

After the Android open failure, what does a call to get_open_error() return? So, something like:

var f = FileAccess.open(path, FileAccess.READ)
if !f:
    print(FileAccess.get_open_error())

That should return an enum value that can be further analyzed here:

@GlobalScope — Godot Engine (latest) documentation in English

jgodfrey | 2023-03-06 19:46

So, I found why it wasn’t working
When trying to do it on res://, it just gives me error code “ERR_CANT_OPEN”/19

lettucing | 2023-03-07 03:35

1 Like
:bust_in_silhouette: Reply From: lettucing

Found the issue, I forgot to add OS.request_permissions() to ask for file access

1 Like