0 votes

I have a txt file in the project directory, and I can read it from the path res://myfile
But when I run on an Android device, it check it with file_exists, it return false, am I miss some permissions?

asked Sep 8, 2017 in Projects by alexzheng (246 points)

Also, I can not read or write to file in user:// on Android.
But it has no problem when run on iOS device.

On Android, when the app exit by press back
exittree will not called, but I can do save work in notification by the notification NOTIFICATIONWMQUITREQUEST.

But the app was force exit, No NOTIFICATIONWMQUIT_REQUEST is received, and no way to save data.

It's very confusing.

Maybe I must save to disk for each change, but this is not good way,

No that is to be expected. Force close is a kill.

So IMHO always save your settings if there's a change wich is worth saving. (level completed, option saved etc.)

I do even rename the previous settings file as a backup (only once per startup) in case that the save-process gets interrupted by a force-close or other event (disk space full). Naturally I then also have to check for integrity when loading the settings on restart and switch to the backup settings file when encountering problems.

2 Answers

0 votes

Before export to .apk, have you tried to include myfile.txt in the "Export"->"Resource" panel?

answered Sep 8, 2017 by jospic (1,444 points)

I have fix read myfile.txt by include *.txt.

But I still can not read or write the file user://settings.cfg for save my settings.

I use ConfigFile, it can work on Mac and iOS.

It is definitely possible to write files to user:// in Android. And it is possible to read files from user:// and res:// as long as they exist.

Naturally, to be able to read files in user:// you'd first have to create one on runtime (file will be persistent).

What is your code for reading/writing?

0 votes

I faced this problem too, so I stuck a lot until I did the following.
1- Change file directory to user: //
2-Copy and paste your txt file where is your project in "user", how to find? just go to C: \ Users \ Lara \ AppData \ Roaming \ Godot \ app_userdata \ ProjectName
3-Va on Export >>> Resource >>> Filters to export non-resource files: type * .txt
Ready :3

answered Aug 11, 2019 by Amigoimaginario (39 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.