summaryrefslogtreecommitdiff
path: root/android-app/app/src/main/kotlin/org/terst
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-05-15 22:13:31 +0000
committerClaude <noreply@anthropic.com>2026-05-15 22:13:31 +0000
commit2d6d686f241cf28afbf1c9c391a3380a0be1e085 (patch)
treeff9e7231d2c5ce240a30409f2df0cdeafab9f695 /android-app/app/src/main/kotlin/org/terst
parentd3dc75f02cec03b04846b4be88902d6b4d6c89de (diff)
fix: target Android 16 correctly for GPX file handler
Android's MimeTypeMap does not include application/gpx+xml for .gpx on all devices, so file managers fall back to text/xml or application/xml. Add intent-filters for both XML MIME types and check OpenableColumns DISPLAY_NAME in code before parsing — so Nav appears in the chooser for XML files but only processes ones named *.gpx. Remove the broken file:// pathSuffix filter (irrelevant on Android 16, also syntactically invalid when combined with mimeType in a single <data> element). Remove unnecessary BROWSABLE category from file-open filters. https://claude.ai/code/session_01DNjbYxiC1cco83dArNGW3G
Diffstat (limited to 'android-app/app/src/main/kotlin/org/terst')
-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) {