0

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

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 卡时,所有图像都消失了,但是除了最近拍摄的图像之外,图像仍然出现在图库中

4

1 回答 1

0

我通过使用这个而不是另一个解决了这个问题sendBroadcast

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

于 2013-08-07T15:14:24.687 回答