Spotify Android Intent Play on Launch

前端 未结 2 1867
闹比i
闹比i 2021-01-16 12:07

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 sear

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-16 13:00

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

提交回复
热议问题