sprestel
sprestel

Reputation: 66

How to query all albums to a given artist

I need a way to display all albums of a given artist. All I found so far ist a way to list all albums which contain at least one songe of the artist - but that's not, what I want. I'm new to android an help would be very appreciated. Thank's in advance!

Upvotes: 2

Views: 3362

Answers (1)

Luminger
Luminger

Reputation: 2194

It may be far to late but it may be interesting to someone else:

I had the same problem and only found obscure solutions how to query all albums done by a specific artist, then I came up with this rather simple solution:

Uri.Builder builder = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI.buildUpon();
builder.appendPath(artistId);
builder.appendPath("albums");

cursor = parent.managedQuery(builder.build(), projection, null,
    null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);

Edit: The above solution to get the Uri may be not the nicest, this should also work:

Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", artistId);

The artistId is the value of the MediaStore.Audio.Artists._ID from a previous Artist query.

Upvotes: 16

Related Questions