From 0429391a784368a6c35809496458d46597b1c873 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Nov 2025 17:55:34 +0000 Subject: [PATCH] Add intent filters to register Shuttle2 as a music player app Fixes #106 This change adds the necessary intent filters and handling code to allow Shuttle2 to be recognized by Android as a music player application. Changes: - Add MUSIC_PLAYER action to register as a music player - Add ACTION_VIEW intent filters for audio file types (audio/*, application/ogg, application/x-ogg, application/itunes) - Update MainActivity to handle ACTION_VIEW intents for audio files - Update PlaybackService to process ACTION_VIEW intents via media session This allows users to: - Set Shuttle2 as the default music player - Open audio files from file managers and other apps with Shuttle2 - Have Shuttle2 recognized by other apps that integrate with music players --- android/app/src/main/AndroidManifest.xml | 22 +++++++++++++++++ .../simplecityapps/shuttle/ui/MainActivity.kt | 24 +++++++++++++++++++ .../playback/PlaybackService.kt | 7 ++++++ 3 files changed, 53 insertions(+) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 63bc49b67..806bf9ec5 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -42,6 +42,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/java/com/simplecityapps/shuttle/ui/MainActivity.kt b/android/app/src/main/java/com/simplecityapps/shuttle/ui/MainActivity.kt index 3e31c0d13..d41b7cc65 100644 --- a/android/app/src/main/java/com/simplecityapps/shuttle/ui/MainActivity.kt +++ b/android/app/src/main/java/com/simplecityapps/shuttle/ui/MainActivity.kt @@ -67,6 +67,7 @@ class MainActivity : AppCompatActivity() { navController.graph = graph handleSearchQuery(intent) + handleViewIntent(intent) billingManager.queryPurchases() @@ -90,6 +91,7 @@ class MainActivity : AppCompatActivity() { super.onNewIntent(intent) handleSearchQuery(intent) + handleViewIntent(intent) } // Private @@ -115,4 +117,26 @@ class MainActivity : AppCompatActivity() { ) } } + + private fun handleViewIntent(intent: Intent?) { + if (intent?.action == Intent.ACTION_VIEW && intent.data != null) { + val uri = intent.data + val mimeType = intent.type + + // Check if this is an audio file + if (mimeType?.startsWith("audio/") == true || + mimeType == "application/ogg" || + mimeType == "application/x-ogg" || + mimeType == "application/itunes") { + ContextCompat.startForegroundService( + this, + Intent(this, PlaybackService::class.java).apply { + action = Intent.ACTION_VIEW + data = uri + type = mimeType + } + ) + } + } + } } diff --git a/android/playback/src/main/java/com/simplecityapps/playback/PlaybackService.kt b/android/playback/src/main/java/com/simplecityapps/playback/PlaybackService.kt index d168284f6..007fc1124 100644 --- a/android/playback/src/main/java/com/simplecityapps/playback/PlaybackService.kt +++ b/android/playback/src/main/java/com/simplecityapps/playback/PlaybackService.kt @@ -187,6 +187,13 @@ class PlaybackService : ACTION_SKIP_PREV -> playbackManager.skipToPrev() ACTION_SKIP_NEXT -> playbackManager.skipToNext(ignoreRepeat = true) ACTION_SEARCH -> mediaSessionManager.mediaSession.controller?.transportControls?.playFromSearch(intent.extras?.getString(SearchManager.QUERY), Bundle()) + Intent.ACTION_VIEW -> { + // Handle opening audio files + intent.data?.let { uri -> + Timber.v("Handling ACTION_VIEW for URI: $uri") + mediaSessionManager.mediaSession.controller?.transportControls?.playFromUri(uri, Bundle()) + } + } } }