get Album Information From Key - Android Media

Android examples for Media:Album

Description

get Album Information From Key

Demo Code


import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;
import java.util.ArrayList;

public class Main{
    public static final String[] projectionAlbums = {
            MediaStore.Audio.Albums.ALBUM,
            MediaStore.Audio.Albums.ALBUM_KEY,
            MediaStore.Audio.Albums.NUMBER_OF_SONGS,
            MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART,
            MediaStore.Audio.Albums.ARTIST };
    public static ArrayList<String> getAlbumInformationFromKey(String key,
            Context context) {/*from ww  w  .ja  va 2 s.c o m*/
        String whereVal[] = { key };

        String where = MediaStore.Audio.Albums.ALBUM_KEY + "=?";

        Cursor albumCursor = PermissionHelper.query(context,
                MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                MusicLibraryHelper.projectionAlbums, where, whereVal, null);

        ArrayList<String> albumInformations = new ArrayList<>();

        if (albumCursor != null) {
            albumCursor.moveToFirst();

            String albumTitle = albumCursor.getString(albumCursor
                    .getColumnIndex(MediaStore.Audio.Albums.ALBUM));
            String albumArt = albumCursor.getString(albumCursor
                    .getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
            String artistTitle = albumCursor.getString(albumCursor
                    .getColumnIndex(MediaStore.Audio.Albums.ARTIST));

            albumInformations.add(albumTitle);
            albumInformations.add(albumArt);
            albumInformations.add(artistTitle);

            albumCursor.close();
        }

        return albumInformations;
    }
}

Related Tutorials