• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Android Android External Storage

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:

  • 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.
All I want to do is be able to save and load files from a folder that I can access. I have other apps on my phone that can read and write files from wherever, so it's definitely not impossible, generally, for an app to possess this capability. But I have spent hours searching and scouring the internet for answers, and I've seen several posts where people discuss it being possible, but none where there is any confirmation that someone has actually done it. I would really like to be told that I'm just missing something stupid here, but from what I've found, it seems like GameMaker Studio may just not actually be capable of reading or writing to external storage -- despite the fact that it has had the checkbox for external storage permissions in the Android options for years, and more recently added the function to explicitly request device permissions. Am I dumb or is this actually broken?

Any insight or advice is appreciated.
 
Last edited by a moderator:
Top