How to start specific songs or find users in Spotify via Android app?

I’m developing an application that interacts with Spotify, and I’m trying to figure out how to prompt the app to play a particular track or search for a user. I’ve experimented with using a Spotify URI like:

String spotifyUri = "spotify:user:someusername";
Uri parsedUri = Uri.parse(spotifyUri);

But this approach merely opens Spotify without triggering any specific action. I found another example that launches Spotify:

Intent spotifyIntent = new Intent(Intent.ACTION_MAIN);
spotifyIntent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
spotifyIntent.setComponent(new ComponentName("com.spotify.mobile.android.ui", "com.spotify.mobile.android.ui.Launcher"));

Unfortunately, this code only starts the app and does not execute a search for a song. Does anyone have guidance on how to modify the intent to search for a track? Any insights are appreciated!

As someone who’s worked extensively with Spotify integration, I can offer some insights. The Spotify Android SDK is your best bet for this task. It provides robust APIs for searching tracks and controlling playback.

To search for a track, you’ll need to use the Spotify Web API. Implement the search endpoint in your app, then use the returned track URI to play it via the SDK.

For user searches, unfortunately, Spotify doesn’t provide a direct method through their public APIs. You might need to implement a workaround, like searching for a user’s public playlists.

Remember to handle authentication properly. Spotify uses OAuth, so you’ll need to set up a proper auth flow in your app.

Lastly, always check Spotify’s developer documentation. They frequently update their APIs, so staying current is crucial.