从库中删除文件夹但图像仍然存在

时间:2013-08-07 14:39:03

标签: android file android-gallery

您好我正在尝试使用此代码从库中删除整个文件夹

public void delete(View view)
{
    deleteDirectory(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Dir"));
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

}

public static boolean deleteDirectory(File path) {
    if( path.exists() ) {
      File[] files = path.listFiles();
      if (files == null) {
          return true;
      }
      for(int i=0; i<files.length; i++) {
         if(files[i].isDirectory()) {
           deleteDirectory(files[i]);
         }
         else {
           files[i].delete();
         }
      }
    }

    return( path.delete() );
  }

当我浏览SD卡时,所有图像都消失了,但图像仍然出现在图库中,除了最近拍摄的图像

1 个答案:

答案 0 :(得分:0)

我使用此代替其他sendBroadcast

来解决问题

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Dir"))));