How to launch Spotify and play specific track from external Android application

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?

You’re mixing different intent actions and using a hardcoded component name that’s probably wrong. Skip MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH with custom components - use Spotify’s URI scheme instead. I ran into this exact issue last year and found Spotify works way better with its native URI format. Build a Spotify URI like “spotify:search:queen bohemian rhapsody” and create an intent with Intent.ACTION_VIEW. This opens Spotify and runs the search, but users might still have to hit play manually depending on their subscription. You could also try the official Spotify Android SDK for more playback control, but that means extra setup and authentication.