Browse Source

Fix drive selection issue on Android

Anish Mishra 2 weeks ago
parent
commit
5bcf9a5a57

+ 2 - 1
doc/classes/DirAccess.xml

@@ -181,7 +181,7 @@
 			<return type="int" />
 			<description>
 				On Windows, returns the number of drives (partitions) mounted on the current filesystem.
-				On macOS, returns the number of mounted volumes.
+				On macOS and Android, returns the number of mounted volumes.
 				On Linux, returns the number of mounted volumes and GTK 3 bookmarks.
 				On other platforms, the method returns 0.
 			</description>
@@ -193,6 +193,7 @@
 				On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]).
 				On macOS, returns the path to the mounted volume passed as an argument.
 				On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
+				On Android (API level 30+), returns the path to the mounted volume as an argument.
 				On other platforms, or if the requested drive does not exist, the method returns an empty String.
 			</description>
 		</method>

+ 5 - 1
platform/android/java/lib/src/org/godotengine/godot/io/directory/FilesystemDirectoryAccess.kt

@@ -159,7 +159,11 @@ internal class FilesystemDirectoryAccess(private val context: Context, private v
 		}
 
 		val storageVolume = storageManager.storageVolumes[drive]
-		return storageVolume.getDescription(context)
+		return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+			storageVolume.directory?.absolutePath ?: ""
+		} else {
+			""
+		}
 	}
 
 	override fun makeDir(dir: String): Boolean {

+ 1 - 1
scene/gui/file_dialog.cpp

@@ -1362,7 +1362,7 @@ void FileDialog::set_access(Access p_access) {
 		case ACCESS_FILESYSTEM: {
 			dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
 #ifdef ANDROID_ENABLED
-			set_root_subfolder(OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DESKTOP));
+			set_current_dir(OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DESKTOP));
 #endif
 		} break;
 		case ACCESS_RESOURCES: {