我使用下面的代码来获取照片的路径和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);
我按路径删除一张照片。 删除一个的缩略图仍然存在。 如何同时删除缩略图?
答案 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
玩的不多,所以这可能是错的。