Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intents to launch song, search for user in spotify app?

I'm trying to figure how apps like Shazam, for example, are able to launch spotify to play a specific song. Another question on SO suggested an intent like String spotifyUri = "spotify:user:username" and then parsing that as a Uri, but instead of searching for a user that just launches spotify. How can I make spotify play a track?

EDIT

Looking at Logcat, it looks like Shazam does this:

Starting: Intent { act=android.media.action.MEDIA_PLAY_FROM_SEARCH cmp=com.spotify.mobile.android.ui/.Launcher (has extras) } from pid 9959

How do I replicate this in my code?

EDIT

Ok, so apparently its something like this:

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

Now how do I tell it to search for a specific song?

like image 995
LuxuryMode Avatar asked Oct 10 '22 20:10

LuxuryMode


1 Answers

Ok, well apparently you need to use a stick a SearchManager.Query as an extra. This post sort of points to that.

So, it's intent.putExtra(SearchManager.QUERY, "michael jackson smooth criminal");

like image 158
LuxuryMode Avatar answered Oct 13 '22 11:10

LuxuryMode