@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] projection = { BaseColumns._ID, AlbumColumns.ALBUM, AlbumColumns.NUMBER_OF_SONGS, AlbumColumns.ARTIST }; if (getArguments() != null) { long artistId = getArguments().getLong((BaseColumns._ID)); Uri uri = Audio.Artists.Albums.getContentUri(EXTERNAL, artistId); String sortOrder = Audio.Albums.DEFAULT_SORT_ORDER; return new CursorLoader(getActivity(), uri, projection, null, null, sortOrder); } return null; }
public void populateTitlesList() { ((TextView) findViewById(R.id.albumName)) .setBackgroundColor(getResources().getColor(R.color.chosen_album_background)); ((LinearLayout) findViewById(R.id.albumsTitles)).removeAllViews(); Cursor albumsCursor; if (0 < m_artistID) { albumsCursor = getContext() .getContentResolver() .query( Audio.Artists.Albums.getContentUri("external", m_artistID), new String[] {Audio.Albums.ALBUM, Audio.Albums._ID}, null, null, null); } else { albumsCursor = getContext() .getContentResolver() .query( Audio.Albums.EXTERNAL_CONTENT_URI, new String[] {Audio.Albums.ALBUM, Audio.Albums._ID}, null, null, null); } StringBuilder ids = new StringBuilder(); for (albumsCursor.moveToFirst(); !albumsCursor.isAfterLast(); albumsCursor.moveToNext()) { ids.append(albumsCursor.getLong(albumsCursor.getColumnIndex(Audio.Albums._ID))); ids.append(','); } ids.deleteCharAt(ids.length() - 1); Log.d("ALBUMS", ids.toString()); Cursor titleCursor = getContext() .getContentResolver() .query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] {Audio.Media.TITLE, Audio.Media._ID, Audio.Media.ALBUM_ID}, Audio.Media.ALBUM_ID + " in (" + ids.toString() + ")", null, // new String[]{}, albumsCursor.getCount() > 1 ? Audio.Media.TITLE : Audio.Media.TRACK); Log.d("ALBUMS", Long.toString(titleCursor.getCount())); populateTitlesListImpl(titleCursor); albumsCursor.close(); }