例如,我试图弄清楚像 Shazam 这样的应用程序如何能够启动 Spotify 来播放特定的歌曲。关于 SO 的另一个问题提出了类似的意图String spotifyUri = "spotify:user:username"
,然后将其解析为Uri
,而不是搜索刚刚启动 spotify 的用户。如何让 Spotify 播放曲目?
编辑
查看 Logcat,看起来 Shazam 是这样做的:
Starting: Intent { act=android.media.action.MEDIA_PLAY_FROM_SEARCH cmp=com.spotify.mobile.android.ui/.Launcher (has extras) } from pid 9959
如何在我的代码中复制它?
编辑
好的,显然它是这样的:
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"));
现在我如何告诉它搜索特定的歌曲?