I’m working on an Android app and I want to integrate with Spotify. My goal is to send a track name from my application to Spotify so it automatically starts playing that song.
I’ve been trying different approaches but can’t get it working properly. Here’s what I attempted:
Intent spotifyIntent = new Intent(Intent.ACTION_VIEW);
spotifyIntent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
spotifyIntent.setComponent(new ComponentName("com.spotify.mobile.android.ui", "com.spotify.mobile.android.ui.Launcher"));
spotifyIntent.putExtra(SearchManager.QUERY, "queen bohemian rhapsody");
startActivity(spotifyIntent);
This code runs without errors but Spotify doesn’t start playing the requested song. I know other apps like SoundHound can do this functionality, so there must be a way to achieve it. What’s the correct approach to trigger Spotify playback from another Android app?