From 04cb4bd2a90c8d981a1d05f4de78e21472ce43e5 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 23 Jan 2023 23:55:21 +0200 Subject: [PATCH] Resolved #7177 - Android custom location save --- .../unciv/app/CustomFileLocationHelperAndroid.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/android/src/com/unciv/app/CustomFileLocationHelperAndroid.kt b/android/src/com/unciv/app/CustomFileLocationHelperAndroid.kt index 83a2b62a02..b87b5fe940 100644 --- a/android/src/com/unciv/app/CustomFileLocationHelperAndroid.kt +++ b/android/src/com/unciv/app/CustomFileLocationHelperAndroid.kt @@ -23,15 +23,17 @@ class CustomFileLocationHelperAndroid(private val activity: Activity) : CustomFi // When we loaded, we returned a "content://" URI as file location. val uri = Uri.parse(suggestedLocation) val fileName = if (uri.scheme == "content") { - val cursor = activity.contentResolver.query(uri, null, null, null, null) - cursor.use { - // we should have a direct URI to a file, so first is enough - if (it?.moveToFirst() == true) { - it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)) - } else { - "" + try { + val cursor = activity.contentResolver.query(uri, null, null, null, null) + cursor.use { + // we should have a direct URI to a file, so first is enough + if (it?.moveToFirst() == true) { + 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 { // if we didn't load, this is some file name entered by the user suggestedLocation