从Android中的MediaStore查询相册

时间:2014-08-05 01:17:14

标签: android android-mediaplayer android-contentprovider android-cursor

我正在为android开发一个简单的媒体应用程序。我想查询设备上可用媒体的相册。当我查询名称的相册时,我成功检索了唯一的名称strong> DISTINCT 关键字,但是当我查询超过1列时,我们还想要其他数据,例如album_art等,它会给出重复值。

这是我的代码

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());
        }

请帮忙 谢谢

1 个答案:

答案 0 :(得分:0)

刚改变了这个

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

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