-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Read and write to app-specific external storage #39414
Comments
I met this issue several days before and it seemed that I walked around it. I had to say I did not know what actually solved the issue but it could possibly be the cause, mentioned by @volzhs at #23004. So, let me repeat what I did. First Shot Godot version: OS/device including version: Results:
the outputs were that not only did it fail to have those two expected permissions, but also it still did not have the permissions even I requested them successfully ("successfully" here means the output returned OK, but when I checked granted_permissions again, permissions not exist). Second Shot I thought maybe it was just the version, and the latest version might solve this issue. Godot version: OS/device including version: Results: Third Shot: Issue Solved I looked around the issues and pulls (e.g. #32600) at the repo regarding read&write permission issues and it came to me that if I did not have those permissions even I enabled them at the android export setting, can I see and edit the AndroidManifest.xml directly to ensure that I do have these permissions? Basically, by following this tutorial, I used the default android build and I only need to click the little android button at the top-right corner to compile, build and run on the Quest. Therefore, I then followed the custom android build. Godot version: OS/device including version: Results: Forth Shot So then, I was wondering this walkaround could work on 3.2.1.stable Godot version: OS/device including version: Results: In a word, check my third shot and sorry that I did not have enough time to explore what was really happening there with the issue, and what I could help is just a walkaround. If you had enough time, probably check all four shots to reproduce my experiments. |
Thanks @Constannnnnt - I'll have a look. |
Hey I ran into this problem in Godot 3.2.1 stable version. |
Yeah @Railwanderer it's still not fixed. You can try @Constannnnnt 's workaround if you need it. |
Yeah I was having this problem: even using adb to give the permission to read external files (and confirming in my game that it had that permission) didn't help and it still would not open files (though it would confirm that they existed, since it would report the 'can't open' error code rather than 'not found'). I'd been using Godot 3.2 and updgrading to 3.2.3 didn't alter anything. So I followed Constannnnnt's solution of enabling the custom android build checkbox. That told me that my Android SDK path was wrong (so I fixed that) and I was missing the JDK (so I fixed that too) and then it built and now loading files from the Download directory just works. So that's good. |
I've figured out the cause, there just needs to be a call to getExternalFilesDir (which creates such directories automatically without storage permissions) ( https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String) ) |
To implement a mechanism for loading content from the server side and saving game settings, I ran into the same problems on the Android platform. I managed to solve the read/write access rights issue, but this solution is relevant for older versions of the system. When trying to write on the Android 11 emulator (API 30), |
I found a very useful comment on stackoverflow. As expected, the fact is that starting with Android 10, there is no longer access to the device's file system outside of the application context. But for now, it is possible to return to the old scheme by adding in AndroidManifest.xml custom build the following attribute in the application tag: <manifest ... >
<!-- This attribute is "false" by default on apps targeting Android Q. -->
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest> |
Godot already has that in android builds by default afaik, and also
I've tested it (with android studio making apps), and the only way to be able to make that directory is by https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String) . I've been trying to make a plugin to make this API call but for some reason my plugin doesn't work (Engine.has_singleton(myPluginName) returns false idk why). Guess I'm stuck with needlessly asking for storage perms til someone makes a plugin and/or Godot gets this API call built in. |
In other words, Android 11 and higher need a platform unification patch. Well, we are waiting :) fortunately, this is not relevant yet, because the transition to a new version of Android is just beginning and the current capabilities of the engine are enough to work correctly with the file system on all previous versions |
@EXOMODE but you said it yourself, "When trying to write on the Android 11 emulator (API 30), Directory.make_dir_recursive() returns an error even after granting access rights." This happens to me on my Android 10 phone, so this works on previous versions (9 and under) without permissions? |
This works on Android 9 and below with the standard permission request via |
My entire point is WITHOUT permissions. It works fine when permission is requested/granted. But what I said here is this API call allows the directory to be made WITHOUT permissions needed.
|
Was this problem solves as to how to successfully read and write to files onto Oculus Quest 2 using the Android Export with Godot? |
Godot version:
3.2.1.rc1
OS/device including version:
Oculus Quest
Issue description:
Per Android documentation, app can store data in external storage without requesting additional permissions as long as it's in the app-specific folder. On the Oculus Quest, this folder is
/sdcard/Android/data/com.yourpackage.name/
.Now, this works if that folder already exists (e.g., created manually with adb). However, I can't create that folder through Godot using
make_dir()
or `make_dir_recursive(). It returns Error 20 (ERR_CANT_CREATE).I would expect that either I can create the folder at that the folder is created automatically once read and write external storage permissions are grated in the Android Manifest.
I'm not sure if this is related to issue #38913 ?
Steps to reproduce:
The text was updated successfully, but these errors were encountered: