On 11 September 2018, we made updates to our iOS and Android SDKs. These new SDKs work for both Spotify Free and Spotify Premium users, offer built-in offline support, and more. Read more about the updates on our blog.
Want to access the 2014 Android streaming SDK? It is available on GitHub by clicking here.

This guide explains how to make remote calls from your app to the Spotify app with the App Remote SDK.

When you make a call via any of the APIs you receive an instance of a CallResult object. CallResult lets you receive results both asynchronously or synchronously. Lets take a look at the example of a synchronous call:

CallResult<PlayerState> playerStateCall = playerApi.getPlayerState();
Result<PlayerState> playerStateResult = playerStateCall.await(10, TimeUnit.SECONDS);
if (playerStateResult.isSuccessful()) {
    PlayerState playerState = playerStateResult.getData();
    // have some fun with playerState
} else {
    Throwable error = playerStateResult.getError();
    // try to have some fun with the error
}

And the preferable async way to do the same thing:

playerApi.getPlayerState()
    .setResultCallback(new CallResult.ResultCallback<PlayerState>() {
        @Override
        public void onResult(PlayerState playerState) {
            // have fun with playerState
        }
    })
    .setErrorCallback(new ErrorCallback() {
        @Override
        public void onError(Throwable throwable) {
            // =(
        }
});

As a result of subscription you receive a Subscription object. For example:

playerApi.subscribeToPlayerState()
    .setEventCallback(new Subscription.EventCallback<PlayerState>() {
        @Override
        public void onEvent(PlayerState playerState) {
            // the Spotify App keeps you updated on PlayerState with this event
        }
    })
    .setErrorCallback(new ErrorCallback() {
        @Override
        public void onError(Throwable throwable) {
            // =( =( =(
        }
    });