summaryrefslogtreecommitdiff
path: root/android-app/app/src/main/kotlin/org
diff options
context:
space:
mode:
Diffstat (limited to 'android-app/app/src/main/kotlin/org')
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt20
1 files changed, 15 insertions, 5 deletions
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt b/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
index 82c238e..07adb35 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
@@ -3,6 +3,7 @@ package org.terst.nav
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
+import android.provider.OpenableColumns
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@@ -141,12 +142,21 @@ class MainActivity : AppCompatActivity(), SafetyFragment.SafetyListener {
private fun handleIncomingGpx(intent: Intent?) {
if (intent?.action != Intent.ACTION_VIEW) return
val uri = intent.data ?: return
- // Accept if the MIME type is gpx-related OR if the URI's last path segment
- // ends in .gpx — some Android versions / file managers send application/octet-stream
- // for file types they don't recognise.
val mime = intent.type ?: contentResolver.getType(uri) ?: ""
- val byExtension = uri.lastPathSegment?.lowercase()?.endsWith(".gpx") == true
- if (!mime.contains("gpx", ignoreCase = true) && !byExtension) return
+ when {
+ // Known GPX MIME types — proceed immediately.
+ mime.contains("gpx", ignoreCase = true) -> Unit
+ // Generic XML MIME (text/xml, application/xml): the Android system MimeTypeMap
+ // often lacks application/gpx+xml for .gpx, so file managers fall back to an
+ // XML type. Verify the display name before parsing to avoid opening random XML.
+ mime.contains("xml", ignoreCase = true) -> {
+ val displayName = contentResolver.query(
+ uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null
+ )?.use { c -> if (c.moveToFirst()) c.getString(0) else null }
+ if (displayName?.lowercase()?.endsWith(".gpx") != true) return
+ }
+ else -> return
+ }
lifecycleScope.launch {
runCatching {
val points = withContext(Dispatchers.IO) {