Android DownloadManager remove() - how to determine when the remove() operation finishes? -


Is there an easy mechanism to determine when a DownloadManager is removed (), because it is partially asynchronous . This function returns immediately with the count of entries in the deleted download table, but the actual file system housekeeping is pushed into some background thread.

The problem is I wrote a little code that looks and removes any existing DownloadManager entry for the file X (and hopefully file system object) before dragging a new copy, unfortunately, The new copy is making this file system in directory before being kicked for the previous incarnation of housekeeping. That is why housekeeping really ends up removing the new version at some point and leaving an orphan entry in the DownloadManager table.

The file system can block in any way until the system is removed.

Debug Code:

  DownloadManager.Query Query = New DownloadManager.Query (). SetFilterByStatus (DownloadManager.STATUS_SUCCESSFUL); Download = getAllDownloadIds (manager.query (query)); Path = activity.getExternalFilesDir (environment. DIRECTORY_DOWNLOADS); // If any file name was passed, remove any existing entry / version of the file if (fileName! = Null & FileName.isEmpty ()) {if (downloads.containsKey (fileName)) {IDs = downloadss.get (file name); (Long ID: ID) {Uri Path = Manager. Zaireford Downloaded File (ID); File checkfile = new file (path.toString ()); Logs. E (TAG, "extracting existing file:" + path. Toastring () + ":" + ID); Int entries are remote = Manager. Back (id); Logs. A (tag, "existing files deleted:" + entries have been removed); }}} ... log. Trying to create a file in V (Tag, "External Memory 'Download' directory:" + path.toString () + "/" + fileName); File = new file (path, filename); Logs. V (TAG, "file already exists:" + file.exists ());   

Example output:

  one ?? | V / Export ?? Extract existing file: file: ///storage/sdcard/Download/appData.csv: 101 â ?? | V / Exportï¹ ?? Existing files deleted: 1â ?? | V / Exportï¹ ?? Trying to create a file in the 'Download' directory on external storage: / storage / sdcard / download / appenda ccv â ?? V / Export ?? What file already exists: True    

I had this same problem - when Instead of the small space, the files in the fast network, the replacement file sometimes arrives within the fraction of each other after calling DownloadManager.remove (...) , in this case, the new arrival The files will be deleted.

The solution I am using is before, when I call DownloadManager.remove (...) , I set up to monitor the file I am I then call the to remove (...) , but then waiting for a delayed event fire before starting the replacement download.

It's finished, classes There are other complex factors - for example, I just put a timeout system, if DownloadManager never removes the file (I can not imagine why this does not happen, but this is not my component).

So in answer to this question, "Is there a simple mechanism .....": There are mechanisms available in you, but unfortunately not particularly easy.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -