从Spotify Intent开始一首歌



无论如何可以从其URI启动Spotify曲目吗?

我尝试了以下方法,但没有一种有效。 当 Spotify 打开时,它总是位于播放列表页面,而不是曲目的播放器。

String spotifyTrackURI = "spotify:track:1cC9YJ8sQjC0T5H1fXMUT2";
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.spotify.mobile.android.ui");
// I've tried with Intent#putExtra()..
launchIntent.putExtra( SearchManager.QUERY, spotifyTrackURI );
// or with setData
launchIntent.setData(Uri.parse(spotifyTrackURI))
context.startActivity(launchIntent);

谢谢

在Freenode(irc)的 #spotify 通道上找到了答案。 谢谢大家!

我把它放在这里让其他人知道:

// right click on a track in Spotify to get the URI, or use the Web API.
String uri = "spotify:track:<spotify uri>"; 
Intent launcher = new Intent( Intent.ACTION_VIEW, Uri.parse(uri) );
startActivity(launcher);

第一个是旧的Spotify版本。对于新版本,您可以使用第二个。

这样,它将首先尝试使用旧版本,

如果失败并出现异常,它将尝试使用第二个版本:)

try {
                final 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, artistName + " " + trackName );
                context.startActivity(intent);
            } catch ( ActivityNotFoundException e ) {
                final 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, artistName + " " + trackName );
                context.startActivity(intent);
            }

如果您在 Spotify 应用程序上获得艺术家的播放列表。您需要开始遵循意图。您不需要打包Spotify的名称或活动。

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("spotify:artist:" + "ARTIST SPOTIFY LINK"));
                startActivity(intent);

最新更新