2011-12-12 75 views
5

是否有任何方法将歌曲标题从我的应用程序发送到Spotify应用程序,以便它可以通过Spotify播放歌曲?将歌曲标题发送到Spotify以开始从Android应用程序播放

我尝试使用我在另一个代码中找到的波纹管代码,但没有任何反应。

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"); 

我知道shazam能够做到这一点。

回答

7

你只是创建一个意图,但你不启动意图。

加入这一行设置你的意图

startActivity(intent); 

所以完整的代码看起来像

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"); 
try { 
    startActivity(intent); 
}catch (ActivityNotFoundException e) { 
    Toast.makeText(context, "You must first install Spotify", Toast.LENGTH_LONG).show(); 
    Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.spotify.mobile.android.ui")); 
    startActivity(i); 
} 
+0

这样一个愚蠢的错误,我不能相信我错过了,谢谢了! – Peter