在启动Android版的Spotify播放意向(Spotify Android Intent Pla

2019-10-21 21:23发布

我想从一个意图推出,但运气不好的时候Spotify的恢复播放。 我觉得我很接近我能得到Spotify的推出,如果我指定一个艺术家它会自动播放一个搜索,但我真的只是希望它恢复我是什么,我还没有得到对工作还没有最后出场。 这个网站做它似乎可能,但与我有什么到目前为止Spotify的只是启动并进入到检索屏幕。 http://developer.android.com/guide/components/intents-common.html#PlaySearch

这是我到目前为止的代码:

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

Answer 1:

我花了一段时间才能弄清楚这一点,所以我想我会后我使用的解决方案。 我通过所有的订阅Intent.ACTION_MEDIA_BUTTON,这是当我发现我需要得到这个工作的组件名称包装循环:

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


Answer 2:

这里是由艺术家搜索和Spotify的播放程序:

public void playSearchArtist(String artist) {
    Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
    intent.setComponent(new ComponentName("com.spotify.music", "com.spotify.music.MainActivity"));
    intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
    intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    intent.putExtra(SearchManager.QUERY, artist);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}


文章来源: Spotify Android Intent Play on Launch