Using Spotify content providers on Android

I was hacking my phone and suddenly found three content providers that Spotify exposes. I googled a bit to figure out if anyone tried to use those. And the answer was - no, no one actually tried. Also no info on developer.spotify.com. After some time I managed to make them work. See below results of my findings.

Prerequisites: you need to have Spotify application installed. I don't know if you need a premium account, but I have one.

Content providers:

 

  1. com.spotify.mobile.android.model.StarredTracksContentProvider - provides access to all starred tracks.
  2. com.spotify.mobile.android.ui.PlaylistSearchProvider - Allows you to search tracks by a keyword. I expected it to search playlists, but probably it's not the case.
  3. com.spotify.mobile.android.ui.SearchProvider - I couldn't figure out this one. 

 

Let's start with the first one.

There are four columns in the table:

  1. _id
  2. name
  3. description
  4. intent

Short example:

 

public void getStarredTracks(Activity activity) {

String providerUri = "content://com.spotify.mobile.android.model.StarredTracksContentProvider";

String[] projection = new String[] { "_id", "name", "description", "intent" };

Cursor cursor = activity.managedQuery(Uri.parse(providerUri), projection, null, null, null);

 

if (cursor != null && cursor.moveToFirst()) {

int id_col = cursor.getColumnIndex("_id");

    int name_col = cursor.getColumnIndex("name");

    int description = cursor.getColumnIndex("description");

    int intent = cursor.getColumnIndex("intent");

do {

Log.d("SP",  "Track ID: " + cursor.getString(id_col));

     Log.d("SP", "Track name: " + cursor.getString(name_col));

   Log.d("SP", "Track description: "+cursor.getString(description));

Log.d("SP", "Intent: "+ cursor.getString(intent));

  } while (cursor.moveToNext());

 }

}

 

The second one has the following columns:

  1. _id
  2. suggest_text_1
  3. suggest_text_2
  4. suggest_intent_data

The code would be more less the same. The URI will be of course different.

String uri = "com.spotify.mobile.android.ui.PlaylistSearchProvider/search_suggest_query";

or

 

String uri = "com.spotify.mobile.android.ui.PlaylistSearchProvider/search_suggest_query/{keyword}";

 

Where {keyword} is, of course a keyword you would like to search against.

 

I hope it may be useful for somebody, it wasn't for me. I wanted to figure out a way to get a list of Spotify playlists into my application.