Spotify Android Intent Play on Launch

前端 未结 2 1870
闹比i
闹比i 2021-01-16 12:07

I\'m trying to get Spotify to resume playback when launched from an intent but not having much luck. I think I\'m close I can get Spotify to launch, and if I specify a sear

2条回答
  •  太阳男子
    2021-01-16 12:42

    Here is a routine for searching by Artist and playing in Spotify:

    public void playSearchArtist(String artist) {
        Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
        intent.setComponent(new ComponentName("com.spotify.music", "com.spotify.music.MainActivity"));
        intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
        intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
        intent.putExtra(SearchManager.QUERY, artist);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }
    

提交回复
热议问题