From 2d6d686f241cf28afbf1c9c391a3380a0be1e085 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 15 May 2026 22:13:31 +0000 Subject: fix: target Android 16 correctly for GPX file handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 element). Remove unnecessary BROWSABLE category from file-open filters. https://claude.ai/code/session_01DNjbYxiC1cco83dArNGW3G --- android-app/app/src/main/AndroidManifest.xml | 18 +++++++++++------- .../src/main/kotlin/org/terst/nav/MainActivity.kt | 20 +++++++++++++++----- 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'android-app') diff --git a/android-app/app/src/main/AndroidManifest.xml b/android-app/app/src/main/AndroidManifest.xml index 35f8dd3..196932d 100644 --- a/android-app/app/src/main/AndroidManifest.xml +++ b/android-app/app/src/main/AndroidManifest.xml @@ -34,26 +34,30 @@ - + - - + - - + - + + + + + + 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) { -- cgit v1.2.3