我已经制作了我的应用所需的图片库活动。一切顺利,除了它显示我的SD卡中包含专辑封面的每张音乐专辑的图像专辑。默认的图库应用程序设法隐藏这些相册图片。我怎样才能实现同样的目标?
我使用以下代码获取图像相册:
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
ArrayList<String> ids = new ArrayList<String>();
if (cursor != null) {
while (cursor.moveToNext()) {
PhotoAlbum album = new PhotoAlbum();
int columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
album.id = cursor.getString(columnIndex);
if (!ids.contains(album.id)) {
//get album name
columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
album.name = cursor.getString(columnIndex);
//get image id for the album cover
columnIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID);
album.coverID = cursor.getInt(columnIndex);
//get filename of album cover image
columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
album.fileName=new File(cursor.getString(columnIndex)).getParentFile().getAbsolutePath();
album.count++; albumList.add(album); ids.add(album.id); album.bm=null;
} else { albumList.get(ids.indexOf(album.id)).count++; }
}
cursor.close();
}