Improved the getFilePathWithFolderFromUri, and getFullFilePathFromFilePath methods to properly resolve the other folders uri.

This commit is contained in:
MohitMaliFtechiz 2024-10-08 17:01:17 +05:30 committed by Kelson
parent 96e9b8913f
commit 946b5cc260

View File

@ -186,7 +186,9 @@ object FileUtils {
var actualFilePath: String? = null var actualFilePath: String? = null
if (filePath?.isNotEmpty() == true) { if (filePath?.isNotEmpty() == true) {
getStorageVolumesList(context).forEach { volume -> getStorageVolumesList(context).forEach { volume ->
val file = File("$volume/$filePath") // Check if the volume is part of the file path and remove it
val trimmedFilePath = filePath.removePrefix(volume)
val file = File("$volume/$trimmedFilePath")
if (file.isFileExist()) { if (file.isFileExist()) {
actualFilePath = file.path actualFilePath = file.path
} }
@ -283,7 +285,9 @@ object FileUtils {
if (pathSegments.isNotEmpty()) { if (pathSegments.isNotEmpty()) {
// Returns the path of the folder containing the file with the specified fileName, // Returns the path of the folder containing the file with the specified fileName,
// from which the user selects the file. // from which the user selects the file.
return pathSegments.drop(1).joinToString(separator = "/") return pathSegments.drop(1)
.filterNot { it.startsWith("0") } // remove the prefix of primary storage device
.joinToString(separator = "/")
} }
return null return null
} }