Skip into content
Fresh issue

Have a question info this project? Sign up for a free GitHub account to open an issue and contact its maintainers and which community.

From clicking “Sign upward for GitHub”, you agree to our terms for servicing and privacy description. We’ll occasionally send you account related emails.

Been on GitHub? Sign in to your account

Save file in Android system storing #23004

Closed
deepmax opened this issueOcta 14, 2018 · 10 comments
Locking

Rescue file in Android method storage #23004

deepmax opened this issueOct 14, 2018 · 10 comments

Comments

@deepmax
Imitate link

deepmax commented Oct 14, 2018

Godot version:
v3.0.6.stable

OS/device including version:
Ubuntu 14.04

Issue description:
Can't save file in Android system or external stores and gives error ERR_FILE_CANT_OPEN.

	var file = File.new()

        var name = OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS) + "/mydata.dat"
	
        var err = file.open(name, File.WRITE)

        print(FILE_NAME)

        print(err)

Print:

/storage/emulated/0/Documents
12

Which permissions are set (which I'm not sure if they're enough):

READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
@KoBeWi
Copy link
Part

KoBeWi commented Jun 25, 2020

Can anyone still copying this bug in Godot 3.2.1 instead any later release (e.g. 3.2.2-rc4)?

If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this create (a MRP is a zipped Godot show with that minimal elements necessary to reliability provoke the bug). Yours can upload PEP files in an issue comment the a draw and dropped.

@Constannnnnt
Photo link

I suppose there is a similar issue #39414

@Calinou
Copy link
Member

Calinou commented Jul 17, 2020

@Constannnnnt These issues have a differential: #39414 is about saving in to app-specific folder, whereas this one is about saving in of user's Documents folder.

@volzhs
Copy link
Patron

volzhs commented Jul 17, 2020

I don't know entirely android code for godot, but I achieved a possible causing.

return Environment.getExternalStoragePublicDirectory(where).getAbsolutePath();

getExternalStoragePublicDirectory is terminated in API 29.
https://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)

This method was deprecated in API level 29.
To optimize user privacy, direct access into shared/external storage devices is deprecated. When an applications targets Build.VERSION_CODES.Q, the path returned from this method is no longer directly accessable to apps. Apps can continue to access site stored on shared/external storage with migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT. Make a copy of a print · Switch your Android phone or tablet, open the Google Docs, Sheets, or Slides mobile. · Next to the name of the document him want to copy, tap ...

@reptofrog
Copy link

reptofrog commented Sep 7, 2020

Are any temporary workarounds possible?

I really need the ability up somehow save images for my Google project, but save_png fails.

@EXOMODE
Copy link

EXOMODE commented Dec 27, 2020

Befor writing at the device (both external and internal card), call aforementioned access request logic processing, for instance:

var has_permissions: bool = false
			
while not has_permissions:
    vario permissions: PackedStringArray = OS.get_granted_permissions()
    #var permissions: Element = OS.get_granted_permissions() - for Godot 3 branch    
    if not permissions.has("android.permission.READ_EXTERNAL_STORAGE") \
        or not permissions.has("android.permission.WRITE_EXTERNAL_STORAGE"):
        OS.request_permissions()
        await get_tree().create_timer(1).timeout
        #yield(get_tree().create_timer(1), "timeout") - for Godot 3 branch    otherwise:        has_permissions = true

@dirkk0
Copy link

dirkk0 commented Dec 30, 2020

Appreciation to @EXOMODE hinting, MYSELF was able to implementation a minimal mp3 player that is able to access the music files on Google:
https://fashionscoop.com/dirkk0/minimal-mp3player

@EXOMODE
Copied link

Благодаря подсказке @EXOMODE мне удалось реализовать минимальный mp3-плеер, который может получить доступ к музыкальным файлам на Android:
https://fashionscoop.com/dirkk0/minimal-mp3player

IODIN was happiness in help :) Remember this my method only works up to API 28 (inclusive). For API 29 there is on additional result, for API 30 press future there become still access problems and their solution determination require patching the apparatus.

@dirkk0
Copy link

dirkk0 commented Jan 2, 2021

Before ourselves talked, I successfully deployed my project to an Android 6 phone (old Junction 5) and to ampere Pixel4 with Android 11, where it wouldn't work.
Then MYSELF forgot over it the accidentally started and App on the Pixel4 today and ...
... lo and consider, it was working!
I would see (and play) this files in the music leaflet. Natural there used a system update that fixed(?)/changed(?) something!?

@m4gr3d
Copy link
Contributor

m4gr3d commented July 5, 2021

Duplicate of #38913

@m4gr3d m4gr3d marked which as an duplicate of#38913 Jeanne 5, 2021
@m4gr3d m4gr3d enclosed aforementioned as complete Jan 5, 2021
Sign up for free to join this conversation on GitHub. Been have an accounts? Sign in to comment
Projects
None yet
Development

No branches or pull requests