Android 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 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 Authentication Library: This library provides a way to obtain OAuth access tokens that can subsequently be used to play music or used in calls to the Spotify Web API.
- Spotify App Remote Library: This library contains classes for playback control and metadata access.
Spotify SDK connects to the Spotify App running in the background
The Spotify 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 SDK, moving from your app to the Spotify app and vice versa is a streamlined experience where playback and metadata always stay in sync.
- 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
- 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 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.
The download packages includes comprehensive documentation of all API classes in the
/docs folder. You can also read the documentation online for the authentication library and for the app remote library.
Please report problems with this SDK through the public issue tracker on GitHub.
Authentication and Authorization
In order to use the SDK, your application will need to get user’s permission to control playback remotely first. This can be done in two ways:
Include the Android Authentication Library in your project
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. the Android Authentication Library can be used to get access tokens that contain
any of our scopes. Our Android SDK Authentication Guide
provides instructions and examples for both methods.
The App Remote portion of the 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 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
SpotifyAppRemote connect/disconnect v0.4.0 vs v0.5.0
// If your code looks like this for v0.4.0: SpotifyAppRemote.CONNECTOR.disconnect(mSpotifyAppRemote); SpotifyAppRemote.CONNECTOR.connect(this, mConnectionParams, mConnectionListener); // you should change it to this as of v0.5.0: SpotifyAppRemote.disconnect(mSpotifyAppRemote); SpotifyAppRemote.connect(this, mConnectionParams, mConnectionListener);
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 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.connect(this, connectionParams, connectionListener);