Skip to content

Native Android client for Spotify, built with Jetpack Compose

Deep links: play once, parse all Spotify hosts, drop autoVerify

liliapke568b9ed8dff
diff --git a/base/app/src/main/AndroidManifest.xml b/base/app/src/main/AndroidManifest.xml
index d486967c..a2ce9e89 100644
--- a/base/app/src/main/AndroidManifest.xml
+++ b/base/app/src/main/AndroidManifest.xml
@@ -77,7 +77,11 @@
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter android:autoVerify="true">
+ <!-- No autoVerify: these are Spotify's domains, verification can never
+ pass for this app. spotify.link is not claimed: the id is only in the
+ redirect target, so the browser resolves it to open.spotify.com,
+ which is claimed and parsed. -->
+ <intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
@@ -93,9 +97,6 @@
<data
android:scheme="https"
android:host="play.spotify.com" />
- <data
- android:scheme="https"
- android:host="spotify.link" />
</intent-filter>
</activity>
diff --git a/base/app/src/main/java/app/myspoti/MainActivity.kt b/base/app/src/main/java/app/myspoti/MainActivity.kt
index ddd6bcc9..c33fe5df 100644
--- a/base/app/src/main/java/app/myspoti/MainActivity.kt
+++ b/base/app/src/main/java/app/myspoti/MainActivity.kt
@@ -85,7 +85,9 @@ class MainActivity : AppCompatActivity() {
watchSession()
watchLoginReturn()
watchLogout()
- handle(intent)
+ // Only on a fresh start: on recreation (theme, locale, process restore)
+ // the same intent would play its link again. New links arrive in onNewIntent.
+ if (savedInstanceState == null) handle(intent)
}
override fun onNewIntent(intent: Intent) {
@@ -194,7 +196,7 @@ class MainActivity : AppCompatActivity() {
/** `https://open.spotify.com/intl-fr/album/{id}?si=…` -> `spotify:album:{id}`. */
private fun spotifyUri(link: String): String? {
- val m = Regex("open\\.spotify\\.com/(?:intl-[a-z-]+/)?(track|album|playlist|artist|show|episode)/([A-Za-z0-9]{22})").find(link) ?: return null
+ val m = Regex("(?:open|www|play)\\.spotify\\.com/(?:intl-[a-z-]+/)?(track|album|playlist|artist|show|episode)/([A-Za-z0-9]{22})").find(link) ?: return null
return "spotify:${m.groupValues[1]}:${m.groupValues[2]}"
}
}