按ID删除缩略图

时间:2012-03-21 06:37:03

标签: android thumbnails

我使用下面的代码来获取照片的路径和ID:

String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.DATA};  
Cursor cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Media._ID); 
int count = cursor.getCount();
int image_column_index = cursor.getColumnIndex(MediaStore.Images.Media._ID); 
int image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
int i;
for(i = 0; i < count; i++) {
cursor.moveToPosition(i);
long id = cursor.getInt(image_column_index);
String p = cursor.getString(image_path_index);
photo.add(id, p);
}

使用以下代码获取缩略图:

bitmap = MediaStore.Images.Thumbnails.getThumbnail(this.getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);

我按路径删除一张照片。 删除一个的缩略图仍然存在。 如何同时删除缩略图?

1 个答案:

答案 0 :(得分:1)

您应该能够使用查询中的id图片(MediaStore.Images.Media._ID列),然后查询MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI以使用MediaStore.Images.Thumbnails.IMAGE_ID删除缩略图等于该id(IMAGE_ID与来自MediaStore.Images.Media._ID的id的id相同)。

long id = cursor.getInt(image_column_index); // this is the id from MediaStore.Images.Media._ID but also the IMAGE_ID from MediaStore.Images.Thumbnails

// if you delete the photo with this above id and also want to delete the thumbnail:
ContentResolver cr = getContentResolver(); // in an Activity
cr.delete(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                MediaStore.Images.Thumbnails.IMAGE_ID + " = ?", new String[] {"" + id});

我对MediaStore玩的不多,所以这可能是错的。