Resolved #7177 - Android custom location save

This commit is contained in:
Yair Morgenstern
2023-01-23 23:55:21 +02:00
parent dd9f946de9
commit 04cb4bd2a9

View File

@ -23,15 +23,17 @@ class CustomFileLocationHelperAndroid(private val activity: Activity) : CustomFi
// When we loaded, we returned a "content://" URI as file location. // When we loaded, we returned a "content://" URI as file location.
val uri = Uri.parse(suggestedLocation) val uri = Uri.parse(suggestedLocation)
val fileName = if (uri.scheme == "content") { val fileName = if (uri.scheme == "content") {
val cursor = activity.contentResolver.query(uri, null, null, null, null) try {
cursor.use { val cursor = activity.contentResolver.query(uri, null, null, null, null)
// we should have a direct URI to a file, so first is enough cursor.use {
if (it?.moveToFirst() == true) { // we should have a direct URI to a file, so first is enough
it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)) if (it?.moveToFirst() == true) {
} else { it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME))
"" } else ""
} }
} }
catch(ex:Exception) {}
suggestedLocation.split("2F").last() // I have no idea why but the content path ends with this before the filename
} else { } else {
// if we didn't load, this is some file name entered by the user // if we didn't load, this is some file name entered by the user
suggestedLocation suggestedLocation