H
Hyper Sarah GX
Guest
I have, for a long time, wanted to create a simple Android app that lets you make pixel art and save it to your device so you can copy it to your PC later. This would be an amazing tool for development since I could just work on game assets anytime, anywhere. The one thing holding this project back is that for several years now, I have not been able to find an answer on how to actually save or load files in external storage on Android. I decided to take another stab at it today, but once again, I've come up empty. So, here's where I'm at:
Any insight or advice is appreciated.
- My app has the "WRITE_EXTERNAL_STORAGE" permission. The checkbox is enabled in Android options in GMS2. I use the function to explicitly request the permission when the app starts, I click "Allow", and the permission is visible under Settings -> My App -> Permissions on my device. Using os_check_permission("android.permission.WRITE_EXTERNAL_STORAGE") == os_permission_granted returns true. There is no question that I have correctly requested and granted this permission within the app.
- My app can save and load image files from the internal storage. Using sprite_save(spr_canvas,0,"output.png") will allow the same file to be found with file_exists("output.png") and loaded in to the game using sprite_add("output.png",1,0,0,0,0), though this is possible without the aforementioned permission.
- My app can recognize a directory located on the root of my phone (external storage). I created a folder on the device manually, and the app is able to find that folder both using directory_exists("/sdcard/My App/") and directory_exists("/storage/emulated/0/My App/").
- My app cannot find a file located within that directory. Both file_exists("/sdcard/My App/test.png") and file_exists("/storage/emulated/0/My App/test.png") return false, even though there is a file called test.png in the folder.
- My app cannot save a new file into that directory. Using sprite_save(spr_canvas,0,"sdcard/My App/output.png") does not create a file in the specified location.
- I did consider the possibility that the sprite_save and file_exists functions were intrepeting the filename as a relative path (creating an /sdcard/My App/ directory in the app's working directory). This would make sense, as both functions are capable of referencing files using relative paths, where directory_exists is not. This does not appear to be the case, however, as calling the file_exists function again still returns false after using sprite_save. Unfortunately, I cannot access the internal storage to definitely verify whether any files have been created or not.
Any insight or advice is appreciated.
Last edited by a moderator: