13

无论如何要从它的 URI 开始一个 Spotify Track 吗?

我尝试了以下方法,但它们都不起作用。当 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);

谢谢

4

3 回答 3

16

在 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);
于 2012-10-03T15:39:31.687 回答
2

第一个是旧的 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);
            }
于 2012-10-02T21:22:45.810 回答
0

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

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("spotify:artist:" + "ARTIST SPOTIFY LINK"));
                startActivity(intent);
于 2015-06-09T19:35:34.383 回答