How do I delete a file from the Android Downloads app?

Making a DownloadManger request is the only way to get the file ID and remove its link in the Downloads application. This is suggested in Clear Android Download List . I have not been able to make this work.

My app is privately distributed and updated when needed. This works well, but I want to programmatically delete the update .apk file when starting a new version. Deletion is successful, but the file remains in the Downloads list. If the user clicks on it, they get a "parsing error" because obviously it is gone. Ugly ...

I would like to clear this. Here's the relevant part of my code (which is called before deleting the file):

public void DoCleanup(Context context) {

   DownloadManager oDM = (DownloadManager)context.getSystemService(android.content.Context.DOWNLOAD_SERVICE);
   Cursor oCur = oDM.query(new DownloadManager.Query().setFilterByStatus(o_DM.STATUS_SUCCESSFUL));

   if (oCur.getCount() > 0) {
      oCur.moveToPosition(-1);
      while (oCur.moveToNext()) {         
         if ( --some condition-- ) { 
            int iRemove = oDM.remove(oCur.getLong(oCur.getColumnIndex(oDM.COLUMN_ID)));            
         }
      }
   } 

}   

      

oCur.getCount () is always 0, even if no filter is installed on the request object. What for? The file is definitely in the folder obtained from Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

.

+3


source to share





All Articles