I wanted to put it into practice in my game so that the player could have saved a TXT file with their Nickname and account password. For this I decided to use the following line to request the storage permission:
Permission request in runtime :
Code: Select all
$ renpy.request_permission("android.permission.WRITE_EXTERNAL_STORAGE")
The problem lies at the time of writing or creating a folder in the player's storage, which I use the following code:
Make directory :
Considering that the "os" module was imported
Code: Select all
def dir_startup():
android_user_path = os.environ["EXTERNAL_STORAGE"] + "/Game Files"
if os.path.exists(android_user_path):
pass ## If the folder exists, it is ignored.
else:
try:
os.mkdir(android_user_path)
print("> Success!")
except Exception as mkerr:
print("> Error :", mkerr) ## Catch the exception without crashing the game.
Code: Select all
def backup_player_id():
android_user_path = os.environ["EXTERNAL_STORAGE"] + "/Game Files"
try:
with open(android_user_path + "/Player ID.txt", "w") as f:
f.write("...") ## Player data is written here.
f.close()
print("> Write success!")
except Exception as writerr:
print("> Error :", writerr)
Code: Select all
[Errno 1] Operation not permitted: u'/sdcard/Game Files/Player ID.txt'
I tried to use the "MANAGE_EXTERNAL_STORAGE" permission to give me more freedom to create those folders and write files, but apparently renpy.request_permission() ignores it and doesn't bring up the request at runtime.
This issue would ruin part of the in-game experience, as I plan to make it possible for players to download the tracks to their device if they wish.
Is there a way for Android to allow me to create folders and write files normally? Or this no longer has a solution?
NOTE : As additional information, I am running these tests on a mobile with Android 11.