Skip to content
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

Add OS.get_external_data_dir() to get Android external directory #49435

Merged
merged 1 commit into from
Jun 10, 2021

Conversation

madmiraal
Copy link
Contributor

Android provides each app with a dedicated location for external storage. However, this was often ignored because any external storage location could be accessed with the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions. With Android 10+, with scoped storage, the dedicated external storage location is the only external location that the app is allowed to access (without using the MediaStore API or requesting the MANAGE_EXTERNAL_STORAGE permission). On Android 10, this could be worked around with android:requestLegacyExternalStorage="true" (see #39103), however this workaround is disabled with Android 11 (see #47954).

This PR provides users with an easy way to locate the dedicated external storage location e.g.:

func _on_Save_Button_pressed():
	var dir = OS.get_external_data_dir()
	var image = $TextureRect.get_texture().get_data()
	image.save_png(dir + "/test.png")

To provide compatibility, on other OSs, this will return the same location as OS.get_user_data_dir().

Fixes #39414.
Should help with #38913 and #48636.

Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, thanks for adding the function! I just add one minor feedback to address, and it should be good for approval!

platform/android/os_android.cpp Outdated Show resolved Hide resolved
@akien-mga akien-mga merged commit bc1fcb9 into godotengine:master Jun 10, 2021
@akien-mga
Copy link
Member

Thanks!

@madmiraal madmiraal deleted the add-android-external-dir branch June 11, 2021 08:13
@m4gr3d
Copy link
Contributor

m4gr3d commented Jul 10, 2021

fyi @akien-mga @madmiraal I'm likely to revert this change and just make get_user_data_dir() behave as expected on Android 10 and higher.

@madmiraal
Copy link
Contributor Author

I'm likely to revert this change and just make get_user_data_dir() behave as expected on Android 10 and higher.

This is one of the many requirements to support Android's scoped storage. It should not be reverted. See my detailed review for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android: Read and write to app-specific external storage
3 participants