Android App Remote SDK Beta

Important: The Android SDK is currently in Beta. The content and functionality is likely to change significantly without warning in future versions.

By using Spotify developer tools, you accept our Developer Terms of Service.

About the SDK

The Spotify App Remote SDK allows your application to interact with the Spotify app running in the background as a service. The capabilities of this API include getting metadata for the currently playing track and context, issuing basic playback commands and initiating playback of tracks.

Spotify App Remote SDK connects to the Spotify App running in the background Spotify App Remote

The Spotify App Remote SDK is a set of lightweight objects that connect with the Spotify app and let you control it while all the heavy lifting of playback is offloaded to the Spotify app itself. The Spotify app takes care of playback, networking, offline caching and OS music integration, leaving you to focus on your user experience. Also, with the App Remote SDK, moving from your app to the Spotify app and vice versa is a streamlined experience where playback and metadata always stay in sync.

Key Features

  • Lightweight library < 300k. No native code or processor architecture dependencies
  • Playback always in sync with Spotify app
  • Processing of playback and caching as well as network traffic is accounted for by the Spotify app
  • Handles system integration such as audio focus, lockscreen controls and incoming calls
  • Automatically handles track relinking for different regions
  • Works offline and online and does not require Web API calls to get metadata for player state

Requirements

  • Minimum Android SDK Version 14
  • Gson (version 2.6.1)

Tutorial and Examples

We provide a Quick Start guide to help you set up your build environment and get started with the Spotify App Remote SDK (Android). It leads you through the creation of a simple app that connects to the Spotify app, plays a playlist and subscribes to PlayerState. Within the download package you will also find a demo app with full source code to help get you started.

API Documentation

The download packages includes comprehensive documentation of all API classes in the /docs folder. You can also read the documentation online.

Issues

Please report problems with this SDK through the public issue tracker on GitHub.

Authentication and Authorization

In order to use the App Remote SDK, your application will need to get user’s permission to control playback remotely first. This can be done in two ways:

Single Sign-On

Include the Android Authentication Library in your project and request app-remote-control scope. This approach is useful if you need to request more scopes or an access token for other purposes, for example to communicate with Spotify Web API. Our Android SDK Authentication Guide provides instructions and examples for both methods.

App Remote Built-in Authorization

The App Remote SDK has a built-in authorization mechanism. To use it, you’ll need to request to show authorization view when connecting to Spotify. The library will automatically request the app-remote-control scope and show the auth view if user hasn’t agreed to it yet. Currently you won’t be able to get the token back from the App Remote SDK. It’s also not possible to request additional scopes. The Quick Start contains an example on how to use this method.

Note: apps cannot be authorized or initiate a connection to start communicating with Spotify unless there is an internet connection.

Terms of Service

Note that by using Spotify developer tools, you accept our Developer Terms of Service.

Frequently Asked Questions

I want the Spotify app to notify my app when Spotify is active. Is it possible?

You can register a broadcast receiver for an action “com.spotify.music.active”. The broadcast is sent when a new track gets on top of the playing queue.

To listen to the broadcast add the next lines to your AndroidManifest.xml file:

<receiver android:name="<ReceiverClassName>">
    <intent-filter>
        <action android:name="com.spotify.music.active"/>
    </intent-filter>
</receiver>

To get more information on BroadcastReceivers, have a look at the docs on the Android developer portal.

Can I use Jackson instead of Gson?

Since version 0.2.0 of the App Remote SDK, Gson is used by default for serializing  and deserializing the request, but the use of Jackson is still supported. If you want to use Jackson, you need to configure it when connecting to Spotify:

ConnectionParams connectionParams =
        new ConnectionParams.Builder(CLIENT_ID)
            .setRedirectUri(REDIRECT_URI)
            .setJsonMapper(JacksonMapper.create())
            .build();

SpotifyAppRemote.CONNECTOR.connect(this, connectionParams, connectionListener);