简体   繁体   中英

Query Albums from MediaStore in android

I am developing a simple application for media in android.I want to query the albums for the media available on device.I am successful retrieving the unique names when I query on name of album with DISTINCT keyword, but we also want the other data like album_art,etc when I query more than 1 columns it gives the duplicate values.

Here is my code

String[] columns = { Albums.ALBUM, Albums._ID, Albums.ARTIST };
        String selection = null;
        String[] selectionArgs = null;
        cursor = resolver.query(EXTERNAL, columns, selection, selectionArgs,
                null);

        if (cursor == null) {

        } else if (!cursor.moveToFirst()) {
            Toast.makeText(context, "No Media on Device", Toast.LENGTH_SHORT)
                    .show();    
        } else {

            do {
                String album_name = cursor.getString(0);
                album = new HashMap<String, Object>();
                album.put("AlbumName", album_name);
                album_list.add(album);
            } while (cursor.moveToNext());
        }

Please help Thank You

Just Changed this

cursor = resolver.query(EXTERNAL, columns, selection, selectionArgs,
                null);

to

cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI, columns, selection, selectionArgs,
                null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM