Skip to content

Conversation

syntaxerror247
Copy link
Member

Fixes #64809

@Alex2782
Copy link
Member

On which devices have you tested it so far? (+Android version)

@syntaxerror247
Copy link
Member Author

On which devices have you tested it so far? (+Android version)

Moto g9 play Android 11 and Android 16 emulator.

@syntaxerror247
Copy link
Member Author

Note: getDrive() method only works on API 30+ because storageVolume.getDirectory() is added in API 30 and I couldn't find any other reliable way to get the drive path on older versions.

Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

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

Tested on Samsung Tab S7, Android 13, changing path to an SD card worked.

I was able to find a code for Android 7-10 to read paths (link), but changing the path didn't work. (see below) If anyone knows the cause, we can create a new PR.


FileDialog test on MacOS

I checked the behavior more closely under macOS with several external USB hard drives; FileDialog::_select_drive requires a path and doesn't work with a name.

void FileDialog::_select_drive(int p_idx) {
	String d = drives->get_item_text(p_idx);
	_change_dir(d);
	filename_edit->set_text("");
	_push_history();
}

Code for Android 7 - 10
	override fun getDrive(drive: Int): String {
		if (drive < 0 || drive >= storageManager.storageVolumes.size) {
			return ""
		}

		val storageVolume = storageManager.storageVolumes[drive]
		return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
			storageVolume.directory?.absolutePath ?: ""
		} else {
			@SuppressLint("DiscouragedPrivateApi")
			try {
				val method = storageVolume.javaClass.getMethod("getPath")
				method.invoke(storageVolume) as? String ?: ""
			} catch (e: Exception) {
				""
			}
		}
	}
image image

@Repiteo Repiteo merged commit 90ba13b into godotengine:master Aug 13, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Aug 13, 2025

Thanks!

@syntaxerror247 syntaxerror247 deleted the drive-selection-issue branch August 14, 2025 02:11
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.

Can't switch to SD card in file dialogs in the Android editor
3 participants