android - how to synchronize file rename/deletion with the file system -


while working android file system, notice issue can't explain myself. changing image using file.renameto() or file.delete() (no matter if image has exifdata) results in following (the methods mentioned above return true):

  • file.renameto(): gallery still shows old name going details , method posted below returns empty thumbnail (sure, because path points file supposed deleted)
  • file.delete(): image gone file system (none of many tested file explorers shows anymore , new file(pathtodeletedimage).exists() returns false) gallery still shows image incl. details

the question: need somehow notify gallery changes performed image file?

the method use thumbnail:

    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 && 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; } 

update

okay, figured out need synchronize file changes file system. guess operations file.delete() , file.renameto() work on linux-level, there's android above. ended resetting nexus 5 after programmatically deleting dcim directory, gallery refused recreate , refused use if recreated manually, camera images blank. clearing cache , rebooting didn't help. if happened on user's device guess developer rating have dropped negative value.

i able figure out how correctly delete images, below code works , changes synced (does not work rename however):

    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); } 

the question now: how delete/rename file/directory changes correctly synced file system?

p.s. yes know how use search, haven't found suitable solution far.

try :) add after work have been finished :) u pass file path u edit

sendbroadcast(new intent(intent.action_media_scanner_scan_file, uri.fromfile(new file(filepath)))); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -