2015-04-23 137 views
0

我使用下面的填充与MICRO_KIND缩略图一个GridView:的Android删除图像文件删除后micro_kind缩略图

/* Find images of interest */ 
    imagecursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CON TENT_URI, 
       columns, 
       MediaStore.Images.Media.DATA + " like ? ", 
       new String[]{"%/houseTab" + currentHouseNumber + "/%"}, 
       null); 

/* Retrieve MICRO_KIND Thumbnails */ 
int id = imagecursor.getInt(image_column_index); 
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
        getActivity().getApplicationContext().getContentResolver(), id, 
        MediaStore.Images.Thumbnails.MICRO_KIND, null); 

的检索过程中完美的作品;该问题发生在我删除实际图像文件时无法删除MICRO_KIND缩略图。这是我现在正在使用的文件图像被删除,但MICRO_KIND不会被删除,即使在刷新后仍然可以在gridview中看到。为了摆脱缩略图,我必须关闭设备或者卸载/挂载SD卡。

int count = imagecursor.getCount(); 
    int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID); 
    ContentResolver cr = getActivity().getApplicationContext().getContentResolver(); 

    for (int i = 0; i < count; i++) { 
     new File(arrPath[i]).delete(); // Delete the actual image file 
     imagecursor.moveToPosition(i); 

     long id = imagecursor.getInt(image_column_index); 

     /* Delete the thumbnails ???? Not working */ 
     cr.delete(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, MediaStore.Images.Thumbnails.IMAGE_ID + 
       "= ?",new String[]{"" + id}); 

顺便说arrPath是使用下面的mediastore检索:

int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); 
arrPath[i] = imagecursor.getString(dataColumnIndex); 

我也尝试以下命令来删除缩略图也没有任何成功。

MediaScannerConnection.scanFile(
      getActivity().getApplicationContext(), 
      new String[]{arrPath[i]}, 
      null, 
      new MediaScannerConnection.OnScanCompletedListener() { 
       @Override 
       public void onScanCompleted(String path, Uri uri) { 
        refreshImages(); 
       } 
      }); 

所以,所以当imagecursor的文件删除后刷新imagecursor是空的,没有返回MICRO_KIND或与此有关的任何数据我如何从数据库中删除该条目???

任何帮助,将不胜感激。

回答

0

希望这会帮助别人。我设法删除从mediastore因此使用MICRO_KIND缩略图条目中的以下内容:

Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
      id); 
    cr.delete(uri,null,null); 
0

我有同样的问题,我找不到任何方式删除MICRO_KIND缩略图不管我做什么,所以我偷看了MediaStore源代码,并看到有/sdcard/DCIM/.thumbnails/.thumbdata3--#####文件的引用,它看起来像是存储MICRO_KIND缩略图的那些文件。

MediaStore数据库保存指向/sdcard/DCIM/.thumbnails文件夹中的缩略图文件的记录,因此,当您从MediaStore中删除缩略图时,它还会删除该文件夹下的文件(该文件似乎是MINI_KIND缩略图,因为它们比MICRO_KIND大得多)。

当我通过ADB删除/sdcard/DCIM/.thumbnails/.thumbdata--BLAHBLAH文件时,它解决了我的问题,加载了正确的缩略图,我注意到文件立即被重新创建。

我也注意到,当我通过ContentResolver像删除文件一样删除文件,然后查询MINI_KIND缩略图时,它们始终正确加载。

所以我的答案(这似乎更像是一个解决方法不是一个答案)是查询从MediaStore的MINI_KIND缩略图,并提取从缩略图:

BitmapFactory.Options opts = new BitmapFactory.Options(); 
opts.inSampleSize = 3; 
Bitmap out = MediaStore.Images.Thumbnails.getThumbnail(contentResolver, imageId, MediaStore.Images.Thumbnails.MINI_KIND, opts); 
out = ThumbnailUtils.extractThumbnail(out, 96, 96); 

并采用user2553585的回答 删除缩略图希望这可以帮助