File not exist on Android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alexzheng
:warning: Old Version Published before Godot 3 was released.

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?

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

alexzheng | 2017-09-08 14:48

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

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

It’s very confusing.

alexzheng | 2017-09-08 15:54

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

alexzheng | 2017-09-08 15:56

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.

wombatstampede | 2017-09-11 09:45

:bust_in_silhouette: Reply From: jospic

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

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.

alexzheng | 2017-09-08 15:11

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

alexzheng | 2017-09-08 15:14

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?

wombatstampede | 2017-09-11 09:39

:bust_in_silhouette: Reply From: Amigoimaginario

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