title: how to synchronize file rename/deletion with the file system
body: <p>While working with android file system, I could notice an issue that I can't really explain to myself. Changing an image by using <code>File.renameTo()</code> or <code>File.delete()</code> (no matter if the image has any <code>Exif</code>data) results in the following (the methods mentioned above return <code>true</code>):</p>
  
  <ul>
  <li><code>File.renameTo()</code>: the Gallery still shows the old name by going to details AND the method posted below also returns an empty thumbnail (sure, because the path points to the file which was supposed to be deleted)</li>
  <li><code>File.delete()</code>: the image is gone from the file system (none of many tested file explorers shows it anymore and <code>new File(pathToDeletedImage).exists()</code> returns <code>false</code>) but the Gallery still shows that image incl. all details</li>
  </ul>
  
  <p>The question: do I need to somehow notify the Gallery about the changes I just performed to an image file?</p>
  
  <p>The method I use to get a thumbnail:</p>
  
  <pre><code>    private Bitmap getThumbnail(ContentResolver cr, String path)
          throws Exception {
  
      Cursor ca = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
              new String[] { MediaStore.MediaColumns._ID },
              MediaStore.MediaColumns.DATA + "=?", new String[] { path },
              null);
      if (ca != null &amp;&amp; ca.moveToFirst()) {
          int id = ca.getInt(ca.getColumnIndex(MediaStore.MediaColumns._ID));
          ca.close();
          return MediaStore.Images.Thumbnails.getThumbnail(cr, id,
                  MediaStore.Images.Thumbnails.MICRO_KIND, null);
      }
  
      ca.close();
      return null;
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Okay, I figured out that we need to synchronize any file changes with the file system. My guess is that operations like <code>File.delete()</code> and <code>File.renameTo()</code> work on the Linux-level, but there's also Android above. I ended up resetting my Nexus 5 after programmatically deleting the <code>DCIM</code> directory, the Gallery just refused to recreate and also refused to use it if I recreated it manually, so all camera images were just blank. Clearing cache and rebooting didn't help. If it happened on a user's device I guess my developer rating would have dropped to a negative value.</p>
  
  <p>I was only able to figure out how to correctly delete images, the below code works and the changes are synced (does not work for rename however):</p>
  
  <pre><code>    private void broadcastScanFile(File f) {
      Intent intentNotifyImgDeleted = new Intent();
      intentNotifyImgDeleted.setType("image/*");
      intentNotifyImgDeleted.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
      intentNotifyImgDeleted.setData(Uri.fromFile(f));
      sendBroadcast(intentNotifyImgDeleted);
  }
  </code></pre>
  
  <p><strong>The question is now: how do I delete/rename any file/directory so the changes are correctly synced with the file system?</strong></p>
  
  <p>P.S. yes I know how to use search, haven't found any suitable solution so far.</p>