2014-02-22 44 views

回答

0

做到這一點 downloadManager.remove(_yourdownloadID);

0

根據文檔說明,您可以撥打remove(downloadID...)

取消下載並將其從下載管理器中刪除。每個下載將在運行時停止,並且不再可通過下載管理器訪問。如果下載的文件部分或完整,則會被刪除。

文檔:http://developer.android.com/reference/android/app/DownloadManager.html#remove(long...)

Query query = new Query();  
query.setFilterById (DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PENDING|DownloadManager.STATUS_RUNNING); 
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
Cursor c = dm.query(query); 
while(c.moveToNext()) { 
    // Here you have all the downloades list which are running, failed, pending 
    // and for abort your downloads you can call the `dm.remove(downloadsID)` to cancel and delete them from download manager. 
    dm.remove(cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID))) 
} 
+0

是的,但從光標c,我如何提取刪除方法所需的ID? – user3140979

+0

當你調用enqueue方法時,它會返回你的下載ID。因此,您必須將這些ID保存在您的共享首選項中,以便將來與這些下載相關的呼叫。 –

+0

我需要從c對象中獲取ID,而不是從入隊。 – user3140979

1

我們應該調用,而不是setFilterById setFilterByStatus。

Button remove = (Button) findViewById(R.id.remove); 
     remove.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       DownloadManager.Query query = new DownloadManager.Query(); 
       query.setFilterByStatus (DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PENDING|DownloadManager.STATUS_RUNNING); 
       DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
       Cursor c = dm.query(query); 
       while(c.moveToNext()) { 
        dm.remove(c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID))); 
       } 
      } 
     }); 
相關問題