在启动Android版的Spotify播放意向 [英] Spotify Android Intent Play on Launch
问题描述
我想从一个意图推出,但运气不好时,Spotify的恢复播放。我想我接近,我可以得到的Spotify推出,如果我指定一个艺术家它会自动播放搜索,但真的我只是希望它恢复我是什么,我还没有得到以工作还没有最后出场。这个网站做它似乎可能,但与我有什么到目前为止只的Spotify启动并进入搜索屏幕。 http://developer.android.com/guide/components/intents-common html的#PlaySearch
下面是我的code迄今:
最终意图intent1 =新意图(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent1.setComponent(新单元名(com.spotify.music,com.spotify.music.MainActivity));
intent1.putExtra(MediaStore.EXTRA_MEDIA_FOCUSvnd.android.cursor.item / *);
intent1.putExtra(SearchManager.QUERY,);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
如果(intent1.resolveActivity(getPackageManager())!= NULL){
startActivity(intent1);
}
我花了一段时间,想出解决办法,所以我想我会后我使用的解决方案。我经历了所有的订阅Intent.ACTION_MEDIA_BUTTON包循环,这是当我发现我需要得到这个工作的组件名称:
私人无效playPlayMusic(){
意图I =新意图(Intent.ACTION_MEDIA_BUTTON);
i.setComponent(新单元名(com.spotify.music,com.spotify.music.internal.receiver.MediaButtonReceiver));
i.putExtra(Intent.EXTRA_KEY_EVENT,新的KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEY code_MEDIA_PLAY));
sendOrderedBroadcast(I,NULL); I =新意图(Intent.ACTION_MEDIA_BUTTON);
i.setComponent(新单元名(com.spotify.music,com.spotify.music.internal.receiver.MediaButtonReceiver));
i.putExtra(Intent.EXTRA_KEY_EVENT,新的KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEY code_MEDIA_PLAY));
sendOrderedBroadcast(I,NULL);
}
I'm trying to get Spotify to resume playback when launched from an intent but not having much luck. I think I'm close I can get Spotify to launch, and if I specify a search for an artist it will auto play but really I just want it to resume what I was last playing which I have not gotten to work yet. This site made it seem possible but with what I have so far Spotify just launches and goes to the search screen. http://developer.android.com/guide/components/intents-common.html#PlaySearch
Here is my code so far:
final Intent intent1 = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent1.setComponent(new ComponentName("com.spotify.music", "com.spotify.music.MainActivity"));
intent1.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "vnd.android.cursor.item/*");
intent1.putExtra(SearchManager.QUERY, "");
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent1.resolveActivity(getPackageManager()) != null) {
startActivity(intent1);
}
Took me a while to figure this out so I thought I would post the solution I used. I looped through all the packages that subscribe to Intent.ACTION_MEDIA_BUTTON and that is when I found the component name I needed to get this to work:
private void playPlayMusic() {
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.setComponent(new ComponentName("com.spotify.music", "com.spotify.music.internal.receiver.MediaButtonReceiver"));
i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY));
sendOrderedBroadcast(i, null);
i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.setComponent(new ComponentName("com.spotify.music", "com.spotify.music.internal.receiver.MediaButtonReceiver"));
i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY));
sendOrderedBroadcast(i, null);
}
这篇关于在启动Android版的Spotify播放意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!