diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-05-12 13:47:09 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-05-12 13:47:09 -1000 |
| commit | 7c82f77cbbc1d5c2664e7a01db30317c42d00525 (patch) | |
| tree | e5d413bcdacfb29a4a421f0203ed9d647f2f670e /android-app/app | |
| parent | 715504566fea6da33c9b5c6093c63375611f9815 (diff) | |
| parent | c30e5089d6e0e30dd9b8c3e6164bd065f393dd7e (diff) | |
Merge: fix MediaStore track loading
Diffstat (limited to 'android-app/app')
| -rw-r--r-- | android-app/app/src/main/kotlin/org/terst/nav/track/TrackStorage.kt | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/track/TrackStorage.kt b/android-app/app/src/main/kotlin/org/terst/nav/track/TrackStorage.kt index 7e9064c..4147128 100644 --- a/android-app/app/src/main/kotlin/org/terst/nav/track/TrackStorage.kt +++ b/android-app/app/src/main/kotlin/org/terst/nav/track/TrackStorage.kt @@ -114,10 +114,16 @@ class TrackStorage(private val context: Context) { private fun loadViaMediaStore(): List<List<TrackPoint>> { val tracks = mutableListOf<List<TrackPoint>>() val uri = MediaStore.Files.getContentUri("external") - val projection = arrayOf(MediaStore.Files.FileColumns._ID) - val selection = "${MediaStore.Files.FileColumns.RELATIVE_PATH} = ? " + - "AND ${MediaStore.Files.FileColumns.DISPLAY_NAME} LIKE ?" - val args = arrayOf("Documents/Nav/", "nav_%.gpx") + val projection = arrayOf( + MediaStore.Files.FileColumns._ID, + MediaStore.Files.FileColumns.RELATIVE_PATH, + MediaStore.MediaColumns.IS_PENDING + ) + // Do NOT filter by RELATIVE_PATH — equality matching is fragile across + // Android versions and devices (trailing-slash normalisation, volume prefix, + // etc.). The display-name pattern is specific enough on its own. + val selection = "${MediaStore.Files.FileColumns.DISPLAY_NAME} LIKE ?" + val args = arrayOf("nav_%.gpx") val cursor = runCatching { context.contentResolver.query(uri, projection, selection, args, null) @@ -126,11 +132,15 @@ class TrackStorage(private val context: Context) { }.getOrNull() NavLogger.i("track", "loadViaMediaStore: cursor=${cursor?.count ?: "null"} rows") cursor?.use { c -> - val idCol = c.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID) + val idCol = c.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID) + val pathCol = c.getColumnIndex(MediaStore.Files.FileColumns.RELATIVE_PATH) + val pendingCol = c.getColumnIndex(MediaStore.MediaColumns.IS_PENDING) while (c.moveToNext()) { - val id = c.getLong(idCol) + val id = c.getLong(idCol) + val path = if (pathCol >= 0) c.getString(pathCol) else "?" + val pending = if (pendingCol >= 0) c.getInt(pendingCol) else -1 val fileUri = android.net.Uri.withAppendedPath(uri, id.toString()) - NavLogger.i("track", "loadViaMediaStore: parsing id=$id uri=$fileUri") + NavLogger.i("track", "loadViaMediaStore: id=$id path=$path pending=$pending") runCatching { val stream = context.contentResolver.openInputStream(fileUri) if (stream == null) { |
