发送歌名Spotify的,开始从Android应用程序打 [英] Send song title to spotify to start playing from android app

查看:113
本文介绍了发送歌名Spotify的,开始从Android应用程序打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从我的应用程序发送一个歌名,以Spotify应用,使其开始通过Spotify的播放歌曲?

Is there any way to send a song title to the spotify app from my app so that it will start playing the song through spotify?

我试着用波纹管code我在另一个code找到,但没有任何反应。

I tried using the bellow code i found in another code but nothing happens.

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的是能够做到这一点。

I know shazam is able to do this.

推荐答案

您刚刚创建一个意图,但你不启动的目的。

You are just creating an Intent, but you don't start the Intent.

设置你的意图后,加入这行

add this line after setting up your intent

startActivity(intent);

因此​​,完整code看起来像

So the complete code would look like that

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

这篇关于发送歌名Spotify的,开始从Android应用程序打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆