Markus
Markus

Reputation: 1767

Spotify Music search intent

I am working on an Android app that launches Spotify and triggers a search (i.e. for "Michael Jackson - Smooth Criminal"). That works pretty well. Unfortunately there is a new app called Spotify Music. All my attempts to trigger a search within that new app failed .. do you have any idea how to achieve that?

Here are the intents that worked for the older versions of Spotify:

/**
     * 
     */
    private void viewOnSpotify() {
        try {
            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"));
            intent.putExtra(SearchManager.QUERY, "Michael Jackson - Smooth Criminal");
            this.startActivity(intent);

        } catch (Exception e) {
            this.viewOnSpotifyFallback();
        }
    }

    /**
     * 
     */
    private void viewOnSpotifyFallback() {
        try {
            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.activity.MainActivity"));
            intent.putExtra(SearchManager.QUERY, "Michael Jackson - Smooth Criminal");
            this.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }

Upvotes: 0

Views: 1928

Answers (1)

Nik Reiman
Nik Reiman

Reputation: 40380

As you noted, there is a new "Spotify Music" app, which has a different package name than the previous (and deprecated) app. The new package name is com.spotify.music, so your intent code should look like this:

intent.setComponent(new ComponentName(
        "com.spotify.music",
        "com.spotify.music.MainActivity"));

Upvotes: 4

Related Questions